10

我想在我的应用程序中允许选择文档(pdf、doc、docx)。我想为此集成 iCloud。我要做的就是从我的应用程序中打开 iCloud 驱动器,用户可以在那里选择文件并返回到原始应用程序。类似whatsapp 已经为iOS 应用程序中的文档选择做了一些事情。

对此有任何想法吗?

4

1 回答 1

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

    }
}
于 2016-05-31T09:14:43.780 回答