Search code examples
iosentitlementsfileprovider-extension

iOS File Provider Extension


I am working on a File Provider Extension for my iOS application. Everything is mostly working, except when I try to save the file to the disk it keeps returning this error:

Error Domain=NSPOSIXErrorDomain Code=2 "couldn't issue sandbox extension com.apple.app-sandbox.read-write for '/Users/Dlabs/Library/Developer/CoreSimulator/Devices/57330867-0570-46C8-8127-CAF8FE9F23A6/data/Containers/Shared/AppGroup/2F5EBE63-6FE5-47AE-BA55-BE47C5ED3FB1/File Provider Storage/0DCCF3F0-083A-4CBB-8C97-E98917DE8C53.jpg/0DCCF3F0-083A-4CBB-8C97-E98917DE8C53.jpg': No such file or directory"

The part that has me stumped is:

couldn't issue sandbox extension com.apple.app-sandbox.read-write

And everytime I google for this error it returns links to Apple, like this one:

https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html

Which explicitly say:

Note: This chapter describes property list keys specific to the macOS implementation of App Sandbox. They are not available in iOS.

Does anybody have experience adding this entitlement?


Solution

  • Ok so it turns out this had nothing to do with entitlements, but rather how I was trying to create a directory in the sandbox.

    Originally did this:

    [_fileManager createDirectoryAtPath:[[url URLByDeletingLastPathComponent] absoluteString]
            withIntermediateDirectories:true attributes:nil error:&dirError];
    

    Should have been done like this:

    [_fileManager createDirectoryAtURL:[url URLByDeletingLastPathComponent]
           withIntermediateDirectories:true attributes:nil error:&dirError];
    

    Notice the difference between createDirectoryAtPath and createDirectoryAtURL

    Anyways hope this helps someone in the future!