在iOS应用中打开iCloud Drive

时间:2016-05-31 09:05:30

标签: ios objective-c iphone icloud icloud-drive

我想在我的应用中允许选择文档(pdf,doc,docx)。我想为此整合iCloud。我想做的就是从我的应用程序打开iCloud驱动器,用户可以选择该文件并返回原始应用程序。类似whatsapp的东西已经在iOS应用程序中进行了文档选择。

有关于此的任何想法吗?

1 个答案:

答案 0 :(得分:17)

请阅读以下链接,您会明白:https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentPickerProgrammingGuide/AccessingDocuments/AccessingDocuments.html

以下是代码:

-(IBAction)iCloudDriveFullFolder:(id)sender{
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.data"]
                                                                                                                inMode:UIDocumentPickerModeImport];
        documentPicker.delegate = self;

  documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
  [self presentViewController:documentPicker animated:YES completion:nil];
}


#pragma mark - iCloud files
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
    if (controller.documentPickerMode == UIDocumentPickerModeImport) {
        //  NSString *alertMessage = [NSString stringWithFormat:@"Successfully imported %@", [url lastPathComponent]];
        //do stuff

    }
}