Saturday, 8 September 2018

File Provider Extension, importDocumentAtURL:: can't read file at given URL (iOS 11.4.1)

I'm having troubles with Paste opertaions into my containers in File Provider extension.

If I paste copied image or text into Files app -> My App -> any folder the file at fileURL can not be read (as a result can't be uploaded to my servers nor stored locally).

- (void)importDocumentAtURL:(NSURL *)fileURL
     toParentItemIdentifier:(NSFileProviderItemIdentifier)parentItemIdentifier
          completionHandler:(void (^)(NSFileProviderItem _Nullable importedDocumentItem, NSError * _Nullable error))completionHandler
{

    NSError *readError = nil;
    NSData *fileData = [NSData dataWithContentsOfURL:fileURL options:NSDataReadingMappedAlways error:&readError];
    NSString *readErrorMessage = readError.localizedDescription;

    NSURL *myFileURL = [NSFileProviderManager.defaultManager.documentStorageURL URLByAppendingPathComponent:@"temp.dat"];
    NSError *copyError = nil;
    BOOL copyResult = [_fileManager copyItemAtURL:fileURL toURL:myFileURL error:&copyError];
    NSString *copyErrorMessage = copyError.localizedDescription;

    ...

Both readErrorMessage and copyErrorMessage are:

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

What am I doing wrong here?

Thanks.

UPD: This happens to any file copied from my container, iCloud container, as well as synthetic files produced from text/image/other data from system Clipboard.



from File Provider Extension, importDocumentAtURL:: can't read file at given URL (iOS 11.4.1)

No comments:

Post a Comment