【发布时间】:2020-02-23 17:16:52
【问题描述】:
完整的错误信息是:
[main] *** 来自 FPBookmarkableStringFromDocumentURL 的错误,file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/MY_APP/hello.txt -> 错误域=NSCocoaErrorDomain 代码=257 “无法打开该文件,因为您无权查看它。”
当我重新启动我的应用程序并尝试重新打开以前打开的文件时(例如,当应用程序处于“后台”状态并释放内存时,从 SceneDelegate(在 iOS 13 中引入)引发此错误,因此我想重新加载状态场景)。 我按照这个 WWDC 会话https://developer.apple.com/videos/play/wwdc2019/212 的步骤和从https://developer.apple.com/documentation/uikit/app_and_environment/scenes/supporting_multiple_windows_on_ipad 下载的示例源代码
我基本上复制了他们的 configure(window: UIWindow?, with activity: NSUserActivity) -> Bool 函数并将其转换为适合我的需要。它似乎可以正常工作,但我遇到了错误。
我正在使用https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/Handoff/AdoptingHandoff/AdoptingHandoff.html#//apple_ref/doc/uid/TP40014338-CH2-SW17 的“在基于文档的应用程序中采用切换”部分中描述的默认 NSUserActivity 技术
这是配置函数的主体:
if activity.activityType == "com.myName.MyApp.openedDocumentUserActivity" {
if let documentURL = activity.userInfo?[UIDocument.userActivityURLKey] as? URL {
if let docBrowserVC = window?.rootViewController as? DocumentBrowserViewController {
documentURL.startAccessingSecurityScopedResource() // tried this, it returns false
docBrowserVC.presentDocument(at: documentURL)
return true
}
}
}
return false
如果有人知道解决方法,谢谢。
【问题讨论】:
-
您对此有什么了解吗?我遇到了同样的问题。
标签: ios swift ios13 nsuseractivity uiscenedelegate