- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在开发一个新的基于文档的应用程序,并且对新的 UIDocumentBrowserController 感到非常高兴...尝试为文档浏览器 UI 推出我自己的解决方案很棘手!
创建文档后,我在让浏览器打开文档时遇到一些问题。
现在发生的情况是,当我选择在文档浏览器中创建新文档时,尽管会记录错误消息,但该文档会按预期创建并打开。但是,在文档关闭后,即使显示了文档,我也无法立即或随后启动时重新打开该文件。然而,这里的一个奇怪的线索是,如果我在创建文档后停止运行应用程序,但没有向其中添加新信息(触发保存周期),并再次运行项目,我可以正确打开文件。这让我认为文件的保存方式存在问题。(注意:在此阶段,我正在努力让本地非/icloud 实现正常工作,然后再继续 icloud 实现。)
以下是将文档保存到磁盘时(或至少在大多数情况下!)代码中任意位置出现的错误消息:2017-06-20 13:21:58.254938-0500 布道设计 2 iOS[22454:5000138] [默认] [错误] 无法获取项目文件的属性值:///Users/stevenhovater/Library/Developer/CoreSimulator/Devices/9A4364F2-B3A1-4AD9-B680-FB4BC876C707/data/Containers/Data/Application/DD534ED8-C4A3-40FE-9777-AED961976878/Documents/Untitled-9.sermon。错误:错误域 = NSFileProviderInternalErrorDomain 代码 = 1“不允许读者访问该 URL。” UserInfo={NSLocalizedDescription=读者无权访问该 URL。}
我怀疑问题出在我的文档类型 plist 中,我尝试通过模仿 wwdc 2017 session 229 视频中的设置来设置它。
我的文档由 NSData 对象封装,使用我认为是 UIDocument 的相当标准的子类实现。 (我省略了生成缩略图的代码)
override func contents(forType typeName: String) throws -> Any {
print("Saving Document Changes")
if sermon != nil {
let newData = NSKeyedArchiver.archivedData(withRootObject: sermon!)
return newData
} else {
let newData = NSKeyedArchiver.archivedData(withRootObject: Sermon())
return newData
}
}
override func fileAttributesToWrite(to url: URL, for saveOperation: UIDocumentSaveOperation) throws -> [AnyHashable : Any] {
let thumbnail:UIImage = self.createThumbnail()
let thumbnaildict = [URLThumbnailDictionaryItem.NSThumbnail1024x1024SizeKey : thumbnail]
let dict = [URLResourceKey.thumbnailDictionaryKey:thumbnaildict]
return dict
}
override func load(fromContents contents: Any, ofType typeName: String?) throws {
guard let newSermon:Sermon = NSKeyedUnarchiver.unarchiveObject(with: contents as! Data) as? Sermon else{
throw documentErrors.invalidFile
}
self.sermon = newSermon
}
在我的 UIDocumentBrowserViewController 子类中,这是我用于获取本地文件名和创建新文档的代码。
func documentBrowser(_ controller: UIDocumentBrowserViewController, didRequestDocumentCreationWithHandler importHandler: @escaping (URL?, UIDocumentBrowserViewController.ImportMode) -> Void) {
var newDocumentURL: URL? = nil
print("creating new local document")
guard let target = self.newLocalFilename() else {
return
}
let targetSuffix = target.lastPathComponent
let tempURL = URL(fileURLWithPath: NSTemporaryDirectory() + targetSuffix)
let newDocument:SDDocument = SDDocument(fileURL: tempURL)
newDocument.sermon = Sermon()
/
newDocument.save(to: tempURL, for: .forCreating) { (saveSuccess) in
/
guard saveSuccess else {
/
importHandler(nil, .none)
return
}
/
newDocument.close(completionHandler: { (closeSuccess) in
/
guard closeSuccess else {
/
importHandler(nil, .none)
return
}
/
importHandler(tempURL, .move)
})
}
}
func newLocalFilename() -> URL? {
let fileManager = FileManager()
guard let baseURL = self.localDocumentsDirectoryURL.appendingPathComponent("Untitled")
else {return nil}
var target = baseURL.appendingPathExtension(DocumentBrowserViewController.documentExtension)
var nameSuffix = 2
while fileManager.fileExists(atPath: target.path) {
target = URL(fileURLWithPath: baseURL.path + "-\(nameSuffix).\(DocumentBrowserViewController.documentExtension)")
nameSuffix += 1
}
let targetSuffix = target.lastPathComponent
print("Target name: \(targetSuffix)")
print("new url: \(target)")
return target
}
最佳答案
经过四五个小时的努力解决这个问题,我发现了一个简单的解决方案:不要在模拟器中进行测试。我转而在我的设备上进行测试,一切立即开始按照广告宣传的那样工作。
[我无法从这里的经验中得出结论,但“在模拟器中不起作用”的问题可能仅限于 Sierra,但模拟器在 High Sierra 中确实有效。这可以解释为什么有些用户看到这个问题而其他用户却没有,尤其是为什么苹果在 WWDC 视频中似乎幸福地没有意识到这个问题。]
关于cocoa-touch - 无法让 UIDocumentBrowserviewController 在基于文档的应用程序中打开文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44665946/
我正在使用 UIDocumentBrowserViewController 构建应用程序。一切正常(位置和文档出现,并且可以创建,可选择) 突然,文档浏览器显示为空。没有地点,没有文件…… 今天之前,
当我使用 UIDocumentBrowserViewController 并获取文件的 documentURL 时,例如“file:///private/var/mobile/Containers/D
我正在开发一个新的应用程序,我希望用户能够从 iCloud 或外部驱动器中选择一个文件夹。如何允许他们使用 UIDocumentBrowserViewController 选择文件夹? 我尝试将 al
我正在使用 UIDocumentBrowserViewController 来存储文档 (iOS 11+) 的“新方式”。无需 iCloud API、权利等——即可正常工作(在单独的文档浏览器进程的控
有什么方法可以禁止在我的基于 UIDocumentBrowserViewController 且还提供 FileProvider 的应用程序中导出文件? 用户只能在应用中查看和编辑文件。 用户应该能够
Apple 的文档很少涉及基于 UIDocumentBrowserViewController 的应用程序,这些应用程序希望支持同时打开多个文档。 我想启用它,以便用户可以轻松地在两个或多个文档之间复
我在 swift 中遇到了 DocumentBrowserViewController 的一些有趣问题,我想停止多个文件选择并隐藏导航栏中的 Salect 按钮。 出于这个原因,我使用了属性 allo
documentBrowser(_:didRequestDocumentCreationWithHandler:) 的文档说,“创建一个新文档并将其保存到临时位置。如果您使用 UIDocument 子
我一直在开发一个新的基于文档的应用程序,并且对新的 UIDocumentBrowserController 感到非常高兴...尝试为文档浏览器 UI 推出我自己的解决方案很棘手! 创建文档后,我在让浏
UIDocumentBrowserViewController 与 UIDocumentPickerViewController 之间有什么区别,目前使用 UIDocumentPickerViewCo
我有一个现有的基于 Objective-C 文档的应用程序,我用新的 UIDocumentBrowserViewController 替换了我以前的文件管理器,一切正常——除了我完全不知道如何使用模板
Apple 表示,为了在"file"应用程序中显示您应用程序的文档,您的 Info.plist 一方面必须打开“支持文档浏览器”,或者“应用程序支持 iTunes 文件共享”另一方面,“支持就地打开文
事实如下:我有一个使用 iOS 11 的 UIDocumentBrowserViewController 的基于文档的应用程序。正如文档中所述,我将其设置为我的 Root View Controlle
我需要检查目录中的文件是否存在并且可以打开,但是我的 FileManager.default.fileExists(atPath: )返回假。我无法获取所选目录中的项目列表,无法检查我的项目是否存在。
我使用 UIDocumentViewController(来自 Xcode 9 模板)为 iOS 11 创建了一个应用程序。我注册了文档类型以支持 .swift 文件(public.swift-scr
我正在尝试将自定义事件添加到我的 UIDocumentBrowserController 长按菜单 - UIActivityViewController。选择默认共享事件后,它会很好地指向用户刚刚长按
在 iOS 13 上测试时,UIDocumentBrowserViewController 遇到了一个非常奇怪的问题。importHandler(newDocumentURL, .move) 似乎无缘
我是一名优秀的程序员,十分优秀!