File Provider Extension

My file provider extension method startProvidingItemAtURL would never get called on tapping of item(image) for some reason. The last call i could see in my extension is providePlaceholderAtURL. Here is the code written in providePlaceholderAtURL. Iam trying to create "File provider storage" directory followed by image file with empty contents before invoking writePlaceholderAtURL:placeholderURL. All i can see is, it is opening empty image file. Please suggest me what went wrong here. Looking for help...


- (void)providePlaceholderAtURL:(NSURL *)url completionHandler:(void (^)(NSError * _Nullable error))completionHandler {

NSFileProviderItemIdentifier identifier = [self persistentIdentifierForItemAtURL:url];

if (!identifier) {

completionHandler([NSError errorWithDomain:NSFileProviderErrorDomain code:NSFileProviderErrorNoSuchItem userInfo:nil]);

return;

}

NSError *error = nil;

NSFileProviderItem fileProviderItem = [self itemForIdentifier:identifier error:&error];

if (!fileProviderItem) {

completionHandler(error);

return;

}


NSURL *placeholderURL = [NSFileProviderManager placeholderURLForURL:url];


NSURL *placeholderDirURL = placeholderURL.URLByDeletingLastPathComponent;


NSError *createError;

if(![_fileManager createDirectoryAtURL:placeholderDirURL withIntermediateDirectories:YES attributes:nil error:&createError]) {

NSLog(@"Error:%@",createError.localizedDescription);

completionHandler(error);

return;

} else {

if(![_fileManager createFileAtPath:url.path contents:nil attributes:nil]) {

NSLog(@"File creation error at:%@",url.path);

}



if (![NSFileProviderManager writePlaceholderAtURL:placeholderURL withMetadata:fileProviderItem error:&error]) {

completionHandler(error);

return;

}


completionHandler(nil);


}

Replies

Hai Raghavendre, i'm trying to implement Files Provider in one of document management app and to my surprise not found any detailed document or relevant tutorial about how to use it.

Can you help me in this or please share relevant tutorial File Provider integration?