以前的好主意。
我做了一些测试..
我确认 iOS 13 的几率和错误。
序言:
我启用了 plist 上的所有标志:
(来自https://forums.developer.apple.com/thread/118932)
...
UIFileSharingEnabled
LSSupportsOpeningDocumentsInPlace
UISupportsDocumentBrowser
..
并在 plist 中添加了所有类型:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>abc File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>org.example.app.document.abc</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>abc File</string>
<key>UTTypeIconFiles</key>
<array/>
<key>UTTypeIdentifier</key>
<string>org.example.app.document.abc</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>abc</string>
</array>
</dict>
</dict>
</array>
我在这里登录:
1)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
print(documentsDir())
if let url = launchOptions?[.url] as? URL {
// TODO: handle URL from here
openWriteAndCloseLog(msg: "1 " + url.absoluteString, withTimestamp: true)
}
return true
}
2)
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
// TODO: handle URL from here
openWriteAndCloseLog(msg: "2 " + url.absoluteString, withTimestamp: true)
return true
}
3)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let url = connectionOptions.urlContexts.first?.url {
// handle
openWriteAndCloseLog(msg: "3 " + url.absoluteString, withTimestamp: true)
}
guard let _ = (scene as? UIWindowScene) else { return }
}
似乎我们只通过了 3(根据我的调试日志,我可以看到内部文档,正如我通过 iTunes 共享的那样)
我做了一个小演示应用来测试它。
https://github.com/ingconti/DocumentBroswerSampleApp
您可以从(例如,mal..)打开附件
你会看到: