美文网首页
iOS - UIDocumentPickerViewContro

iOS - UIDocumentPickerViewContro

作者: aven_kang | 来源:发表于2022-05-26 09:25 被阅读0次
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

相关文章

网友评论

      本文标题:iOS - UIDocumentPickerViewContro

      本文链接:https://www.haomeiwen.com/subject/npiodrtx.html