We are presenting a UIDocumentPickerViewController
with the URL to the URLForUbiquityContainerIdentifier
and for whatever reason, it does not show the cancel button for all our users. Sometimes, it is completely missing and a user cannot dismiss without going to the "Recent" tab where it will force the cancel button to appear.
Here is how we present the modal:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self rootDirectoryForICloudWithFolderName:@"Test" createFolder:YES completion:^(NSURL *ubiquityURL) {
self.picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeJPEG] inMode:UIDocumentPickerModeOpen];
self.picker.directoryURL = ubiquityURL;
self.picker.delegate = self;
[self presentViewController:self.picker animated:YES completion:nil];
}];
});
}
- (void)rootDirectoryForICloudWithFolderName:(NSString *)folderName createFolder:(BOOL)createFolder completion:(void (^)(NSURL *))completionHandler {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *rootDirectory = [[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@", folderName]];
if (rootDirectory) {
if (![[NSFileManager defaultManager] fileExistsAtPath:rootDirectory.path isDirectory:nil] && createFolder) {
[[NSFileManager defaultManager] createDirectoryAtURL:rootDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(rootDirectory);
});
});
}
I am setting the directoryURL to the ubiquity URL for the iCloud documents folder for our app. The strange thing is, this only happens on a new install with a unique bundle identifier. If I switch tabs, to make the cancel button appear, then on the next launch it will work correctly. But, changing the bundle identifier will cause the bug to happen again.
Apple has said this is a bug, but it still remains unfixed in iOS 14 beta 5. Can anyone think of a workaround for this issue as we would love to use this feature!