I have an iOS app which has an action extension to save documents in it.
The method startAccessingSecurityScopedResource()
returns false in some cases even when I am able to access the file.
BOOL success = [originalURL startAccessingSecurityScopedResource];
if (success) {
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
NSError *error = nil;
[fileCoordinator coordinateReadingItemAtURL:originalURL options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
//My Code
}
}
In the above code, the following is observed
When sharing a file from Apple's Photos App
originalURL = file:///var/mobile/Media/PhotoData/OutgoingTemp/49152B46-E719-41A5-A5D5-21EAE6254246/RenderedPhoto/IMG_0026.JPG
When sharing a file from MS Word App
originalURL = file:///private/var/mobile/Containers/Data/Application/1B0C962F-E7B4-46ED-A9DA-A8213E05A470/tmp/ShareAttachments/%7BC699DC26-37F9-A949-8F69-1F9D6981C4B0%7D/Document.docx
When sharing a file from Apple's Pages App
originalURL = file:///private/var/mobile/Containers/Data/Application/CDBBDC79-02C7-4ABF-A6B9-F38B6540E2B1/Documents/Document%20(1).pages
The flag success
is true
in the first case (Photos App), but is false
in the other two (Word & Pages App).
If I remove the success flag check, I am able to access all the three files using the NSFileCoordinator and am able to copy the file into my app.
Therefore, I am not sure why is the method startAccessingSecurityScopedResource()
returning false for a scenario where I clearly have the access to copy the file.
The motive is to save the file exported from the file editor app into my iOS app using the action extension.