Ios UIDocumentPickerViewController-所有文件均灰显
我正在测试iOS 8中新的Ios UIDocumentPickerViewController-所有文件均灰显,ios,ios8,Ios,Ios8,我正在测试iOS 8中新的UIDocumentPickerViewControllerAPI。我想在iCloud中打开一个文件,看看交互是如何工作的 这是我从我的UIViewController运行的代码: - (IBAction)openDocument:(id)sender { [self showDocumentPickerInMode:UIDocumentPickerModeOpen]; } - (void)showDocumentPickerInMode:(UIDocumen
UIDocumentPickerViewController
API。我想在iCloud中打开一个文件,看看交互是如何工作的
这是我从我的UIViewController
运行的代码:
- (IBAction)openDocument:(id)sender {
[self showDocumentPickerInMode:UIDocumentPickerModeOpen];
}
- (void)showDocumentPickerInMode:(UIDocumentPickerMode)mode {
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeData] inMode:mode];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
openDocument
绑定到IB中的一个按钮。当我点击它时,它会打开iCloud浏览器,但其中的每个文件夹都会变灰(我创建了一些测试注释记号、数字和页面文件),因此我无法访问这些文件:
我检查了一些文档并做了以下工作(运气不佳):
- 在我的应用程序中启用iCloud(在“功能”部分,用于键值存储和iCloud文档)
- 在my Info.plist中添加了公共数据的UTI,如下所示:
<key>CFBundleDocumentTypes</key>
CbundleTypeConfigile icon.png CbundleTypeName 我的数据 CbundleTypeRole 观众 lsItemContentType 公共数据 L类型包装 NSDocumentClass 文件 NSPersistentStoreTypeKey 二元的CbundleDocumentTypes
- 将值为
的YES
键添加到my Info.plistnsubiquitouscontainersdocumentscopepublic
你知道哪里有错或遗漏吗?我的工作文档不符合
kUTTypeData
,它们符合kUTTypePackage
然而,在iOS 8 beta 3中,我必须使用精确的UTI:
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.apple.iwork.pages.pages", @"com.apple.iwork.numbers.numbers", @"com.apple.iwork.keynote.key"] inMode:mode];
将打开并提供对驱动器上所有项目的访问
//open document picker controller
func openImportDocumentPicker() {
let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
self.present(documentPicker, animated: true, completion: { _ in })
}
/*
*
* Handle Incoming File
*
*/
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
if controller.documentPickerMode == .import {
let alertMessage: String = "Successfully imported \(url.absoluteURL)"
}
}
/*
*
* Cancelled
*
*/
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("Cancelled")
}
您的图像不显示灰显文件。如果打开文件夹会发生什么情况?文件夹变灰,我无法访问文件。刚刚添加了一个澄清。@pgbHave你测试过beta 3版本吗?@karan还没有。我无法将我的项目与最新的Xcode链接…@pgb感谢您的回复。我还在我的应用程序中使用UIDocumentPickerViewController。我遵循了上述步骤,但在演示UIDocumentPicker应用程序时出现错误“UIDocumentPicker缺少icloud Entitment”。我将icloud启用到我的项目中。你能用最新的测试版测试你的项目吗?它似乎也出现在测试版4中。它也出现在测试版5中。谢谢你的回答!你是怎么知道苹果自己的应用程序的UTI的?那是在什么地方出版的吗?再次感谢!您可以使用
mdls
命令查看文件的UTI。在Mac上创建的iWork文件也有ZIP文件格式,但保存在iCloud中的文件似乎总是使用包格式。当我使用这些UTI时,iWork文件夹可以打开,但在点击文件时什么都不会发生。我已经实现了documentPicker DidPickDocumentTurl,它没有被称为正确。非常感谢。高兴的我可以帮你。公众伪造物品!
//open document picker controller
func openImportDocumentPicker() {
let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
self.present(documentPicker, animated: true, completion: { _ in })
}
/*
*
* Handle Incoming File
*
*/
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
if controller.documentPickerMode == .import {
let alertMessage: String = "Successfully imported \(url.absoluteURL)"
}
}
/*
*
* Cancelled
*
*/
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("Cancelled")
}