dismissGrantingAccessToURL:失败 "didPickDocumentURLs called with nil or 0 URLS"

dismissGrantingAccessToURL: failing with "didPickDocumentURLs called with nil or 0 URLS"

我有一个 iOS 应用程序,它提供的文档选择器功能在 iOS 10 上完美运行,但在 iOS 11 上总是调用 documentPickerWasCancelled: 并在日志:

[UIDocumentLog] UIDocumentPickerViewController : didPickDocumentURLs called with nil or 0 URLS

我在提供商扩展上使用有效的 NSURL 正确地调用了 dismissGrantingAccessToURL:,但它从未调用另一端的 documentPicker:didPickDocumentsAtURLs:

我想我漏掉了什么,你能给我解释一下这种不良行为吗?

我遇到了同样的问题。不幸的是,我认为这个解释是 iOS 11 中的错误或向后不兼容。根据文档,文档选择器扩展应该足够了:

"The Document Picker View Controller extension can perform import and export operations on its own. If you want to support open and move operations, you must pair it with a File Provider extension."

https://developer.apple.com/documentation/uikit/uidocumentpickerextensionviewcontroller?language=objc

事实上,这在 iOS 10 及更早版本中运行良好。 iOS 11 可能意味着与现有的无 FileProvider DocumentPickers 向后兼容,但似乎并非如此。或者他们可能忘记更新文档了。

相反,可以实现新的更新文件提供程序,通过标准文档浏览器提供对文件的访问权限 UI:

https://developer.apple.com/documentation/fileprovider

这确实适用于支持 iOS10 选择器的 iOS 11 FileProvider。您可能想使用新的 Xcode 模板创建一个新的 FileProvider,然后使用 :

@available(iOSApplicationExtension 11.0, *)

在 FileProviderItem 和 FileProviderEnumerator 类 上,然后:

if #available(iOSApplicationExtension 11.0, *) {

在 FileProviderExtension 的方法中

我发现我的 iOS 10 选择器确实正确地调用了这个方法,但请注意 completionHandler?(nil) 是让它工作所必需的。默认情况下,iOS11 的模板会插入一个报告失败的完成。此代码对我有用:

    override func startProvidingItem(at url: URL, completionHandler: ((_ error: Error?) -> Void)?) {

            completionHandler?(nil)

    //        completionHandler?(NSError(domain: NSCocoaErrorDomain, code: NSFeatureUnsupportedError, userInfo:[:]))

}

但是,iOS10/11 不兼容问题还没有结束。如果您创建一个 iOS10/11 兼容的文件提供程序,据我所知,它不会在某些 iOS10 台设备上 运行。我可以 运行 或在 32 位 iOS 设备上调试我的设备,但 FileProvider 在 64 位 iOS 10 设备上崩溃并出现此错误:

dyld: Library not loaded: /System/Library/Frameworks/FileProvider.framework/FileProvider
  Referenced from: /private/var/containers/Bundle/Application/61BBD1A7-EA1E-4C10-A208-CA1DFA433C8D/test.app/PlugIns/testFileProvider.appex/testFileProvider
  Reason: image not found