NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code ", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];
UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];
documentPickerViewController.delegate = self;
[self presentViewController:documentPickerViewController animated:YES completion:nil];
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
// NSArray *array = [[url absoluteString] componentsSeparatedByString:@"/"];
// NSString *fileName = [array lastObject];
// fileName = [fileName stringByRemovingPercentEncoding];
// NSLog(@"--->>>>%@",fileName);
// if ([iCloudManager iCloudEnable]) {
// [iCloudManager downloadWithDocumentURL:url callBack:^(id obj) {
// NSData *data = obj;
// UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"icloud" message:@"写入沙河" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
// [alert show];
// //写入沙盒Documents
// NSString *path = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@",fileName]];
// [data writeToFile:path atomically:YES];
// }];
// }
}
+ (BOOL)iCloudEnable {
NSFileManager *manager = [NSFileManager defaultManager];
NSURL *url = [manager URLForUbiquityContainerIdentifier:nil];
if (url != nil) {
return YES;
}
NSLog(@"iCloud 不可用");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"icloud" message:@"iCloud 不可用" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
return NO;
}

截屏2022-03-20 上午11.58.09.png
网友评论