gpt4 book ai didi

ios - 文件未使用 NSFileProviderExtension 显示

转载 作者:行者123 更新时间:2023-11-28 06:10:08 26 4
gpt4 key购买 nike

我正在尝试实现 NSFileProviderExtension,第一步,我只是尝试显示单个项目。

我在我的扩展中覆盖了这个方法:

override func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier) throws -> NSFileProviderEnumerator {
var maybeEnumerator: NSFileProviderEnumerator? = nil
if (containerItemIdentifier == NSFileProviderItemIdentifier.rootContainer) {
// TODO: instantiate an enumerator for the container root
print("Root Container")
maybeEnumerator = FileProviderEnumerator(enumeratedItemIdentifier: NSFileProviderItemIdentifier(rawValue: "rootContainer"))
} else if (containerItemIdentifier == NSFileProviderItemIdentifier.workingSet) {
// TODO: instantiate an enumerator for the working set
print("Working Set")
} else {
// TODO: determine if the item is a directory or a file
// - for a directory, instantiate an enumerator of its subitems
// - for a file, instantiate an enumerator that observes changes to the file
print("Other Stuff")
}
guard let enumerator = maybeEnumerator else {
print("Enumerator Is nil, Throwing Error")
throw NSError(domain: NSCocoaErrorDomain, code: NSFeatureUnsupportedError, userInfo:[:])
}
return enumerator
}

FileProviderEnumerator 中的这个方法:

    func enumerateItems(for observer: NSFileProviderEnumerationObserver, startingAt page: NSFileProviderPage) {
/* TODO:
- inspect the page to determine whether this is an initial or a follow-up request

If this is an enumerator for a directory, the root container or all directories:
- perform a server request to fetch directory contents
If this is an enumerator for the active set:
- perform a server request to update your local database
- fetch the active set from your local database

- inform the observer about the items returned by the server (possibly multiple times)
- inform the observer that you are finished with this page
*/


let items = [FileProviderItem(id: "1", name: "1_file")]
observer.didEnumerate(items)
print("Finish Enumerating")
observer.finishEnumerating(upTo: nil)
}

现在没有任何显示。我还应该做些什么来只显示一个项目吗?

最佳答案

答案在这里: Items in File provider extension for ios 11

您必须实现 itemIdentifier、filename、typeIdentifier 和 parentItemIdentifier 属性才能显示 FileProviderItem。它们是必需的,其他属性是可选的。

当用户在文件应用中打开您应用的文件提供程序时,系统会调用enumerator(for:) 方法并传递rootContainer 常量。因此,您必须为根级文件夹中的项目将 parentItemIdentifier 设置为 NSFileProviderItemIdentifier.rootContainer

如果您执行上述操作,您的项目将会显示。

关于ios - 文件未使用 NSFileProviderExtension 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46985992/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com