When pick the file with the native app "Files" invoke my app and get the path:

file:///private/var/mobile/Containers/Shared/AppGroup/F9BF9D9E-4756-40ED-85A4-810B4D1A67CB/File%20Provider%20Storage/myFile.abcd

I catch the path in the string "originalPath"

NSURL *originalURL = [NSURL URLWithString:originalPath];
NSURL *destinationURL = [NSURL URLWithString:destination]; //This is a path in the cache folder of my app

BOOL success = [originalURL startAccessingSecurityScopedResource];

NSError *error;

NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];

[fileCoordinator coordinateReadingItemAtURL:originalURL options:NSFileCoordinatorReadingWithoutChanges writingItemAtURL:destinationURL  options:NSFileCoordinatorWritingForReplacing  error:&error byAccessor:^(NSURL *newURL, NSURL *newWritingURL) {

[[NSFileManager defaultManager] copyItemAtPath:newURL.path toPath:newWritingURL.path error:&error];

if (success) {
   [originalURL stopAccessingSecurityScopedResource];
 }
}
];

The value of the error.localizerDescription

The file “myFile.abcd” couldn’t be opened because you don’t have permission to view it.

In the console I can see:

filecoordinationd   Claim 97D67388-49D7-4076-9622-0FD18C9DE063 granted in server    14:15:47.421475-0700
filecoordinationd   Claimer for 97D67388-49D7-4076-9622-0FD18C9DE063 is waiting for provider com.apple.FileProvider.LocalStorage to provide 14:15:47.421495-0700
filecoordinationd   Hit the server for a process handle 9fc643c000014c6 that resolved to: [application<com.mydomain.myappname>:5318]    14:15:47.421516-0700
filecoordinationd   Caching handle <private>, with ipc id 9fc643c000014c6, and pid 5318 14:15:47.421535-0700
fileproviderd   com.apple.FileProvider.LocalStorage providing <private> for claim 97D67388-49D7-4076-9622-0FD18C9DE063  14:15:47.421832-0700
fileproviderd   com.apple.FileProvider.LocalStorage began providing 14:15:47.421853-0700
filecoordinationd   Claim 97D67388-49D7-4076-9622-0FD18C9DE063 granted in server    14:15:47.421475-0700
filecoordinationd   Claimer for 97D67388-49D7-4076-9622-0FD18C9DE063 is waiting for provider com.apple.FileProvider.LocalStorage to provide 14:15:47.421495-0700
filecoordinationd   Hit the server for a process handle 9fc643c000014c6 that resolved to: [application<com.mydomain.myappname>:5318]    14:15:47.421516-0700
filecoordinationd   Caching handle <private>, with ipc id 9fc643c000014c6, and pid 5318 14:15:47.421535-0700
fileproviderd   com.apple.FileProvider.LocalStorage providing <private> for claim 97D67388-49D7-4076-9622-0FD18C9DE063  14:15:47.421832-0700
fileproviderd   com.apple.FileProvider.LocalStorage began providing 14:15:47.421853-0700
filecoordinationd   Claim D578716E-D91A-4ECB-9348-CF9824341DA9 invoked in server    14:15:47.421862-0700
myAppName   Claim D578716E-D91A-4ECB-9348-CF9824341DA9 granted in client    14:15:47.421880-0700
myAppName   Claim D578716E-D91A-4ECB-9348-CF9824341DA9 invoked in client    14:15:47.421923-0700

On call startAccessingSecurityScopedResource always get FALSE, inside the Accessor in the fileCoordinator never can see the originaURL.

Is there an other way to read the file, can I request a permission?

0

There are 0 answers