I was developing an Mac application recently and came across the problem, which was quite interesting and i thought I can share my experience with you guys.
ok, let me directly get it stright. Recently I developed a Mac application for binary resigning, the functionality of the app is to take your ipa files and resign it with different certificates and provision profiles.
I developed this app successfully and tried to publish on app store using app Store connect. But when I try to push the app to App Store, Apple didn’t allow me to publish stating the reason “I am not using App Sandbox in my application”. Problem is my app needs to access resources outside of the sandbox, if I enable sandbox I won’t be able to access system directories like “~/Library/MobileDevice/’Provisioning Profiles”, which is essential for resigning. I did some research and found a solution, which is what I am about to explain below.
1) Enable sand box to your application under signing and capabilities

2) Update your entitlement files

All three items are mandatory. com.apple.security.files.bookmarks.app-scope will allow to bookmark urls outside of the sandbox and com.apple.security.files.user-selected.read-write will allow to read and write files outside of the sand box. using the combination of these three permissions we will be accessing files outside of the sand box.
- First we will request read and write access for a specific directory
- Then bookmark that directory and save it to local storage
- Using startAccessingSecurityScopedResource function we will access system directories out side of sand box.
I wrote a simple code snippet for this solution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
override func viewDidLoad() { super.viewDidLoad() let directoryURL = URL(string: "~/Library/MobileDevice/'Provisioning Profiles'") let openPanel = NSOpenPanel() openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = true openPanel.canCreateDirectories = false openPanel.canChooseFiles = false openPanel.prompt = "Grant Access" openPanel.title = "We need to access Provisioning Profiles for resigning. Please grand access to your Provisioning Profiles directory.." openPanel.message = "We need to access Provisioning Profiles for resigning. Please grand access to your Provisioning Profiles directory.." openPanel.directoryURL = directoryURL openPanel.begin { [weak self] result in guard self != nil else { return } guard result == .OK, let url = openPanel.url else { return } self?.accessbookmarkfiles(url: url) } } func accessbookmarkfiles(url: URL){ do { let data = try url.bookmarkData(options: [.withSecurityScope]) UserDefaults.standard.set(data, forKey: "profileUrl") guard let bookmarkData = UserDefaults.standard.data(forKey: "profileUrl") else { print("data not valid"); return } var isStale = true let url = try URL(resolvingBookmarkData: bookmarkData, options:[.withSecurityScope], bookmarkDataIsStale: &isStale) let _ = url.startAccessingSecurityScopedResource() let directoryContents = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: []) print(directoryContents) url.stopAccessingSecurityScopedResource() } catch { print(error.localizedDescription) } } |
Hope this will be helpful for you guys. Happy Coding 😁!!!