I'm allowing my users to select multiple iCloud documents to compare side by side. I would like the user to select the file and it copy locally and then display it in the WKWebView. In the simulator it works perfectly. However, on the device it will not display the documents at all. Any ideas?
-(void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray *)urls{
// check
if(controller.documentPickerMode == UIDocumentPickerModeOpen){
// vars
NSURL *url = [urls objectAtIndex:0];
BOOL isAccess = [url startAccessingSecurityScopedResource];
// check
if(!isAccess){
// return
return;
}
// vars
NSString *fileName = [NSString stringWithFormat:@"%@.%@", [appDelegate.myGlobals getGuid], url.pathExtension];
NSString *path = [url path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
NSString *documentsPath = [[self applicationDocumentsDirectory].path stringByAppendingPathComponent:fileName];
NSURL *fileURL = [NSURL fileURLWithPath:documentsPath];
// write
[data writeToFile:documentsPath atomically:YES];
// set
NSURL *url = [NSURL URLWithString:fileURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:urlRequest];
// stop
[url stopAccessingSecurityScopedResource];
}
}