在我的文件提供程序扩展中,我想在我的NoteProvider扩展中执行移动操作。
我可以通过拖动操作在任何文件夹上方移动任何文件,它可以正常工作但是当我尝试通过操作显示在波纹管屏幕中“移动”时,screen2 显示和其他扩展已启用,但我的NotProvider扩展已禁用。
我的代码是FileProviderItem
class FileProviderItem: NSObject, NSFileProviderItem {
public var id: String?
public var name: String?
var childItemCount : NSNumber?
var documentSize: NSNumber?
var creationDate : Date?
var contentModificationDate : Date?
var lastUsedDate: Date?
var isDownloaded: Bool = false
public var fTypeIdentifier: String?
var pid : NSFileProviderItemIdentifier!
var parentItemIdentifier: NSFileProviderItemIdentifier {
return pid
}
var typeIdentifier: String {
return fTypeIdentifier! // for folder = "public.folder", for file = file type UTI
}
var itemIdentifier: NSFileProviderItemIdentifier {
return NSFileProviderItemIdentifier(self.id!)
}
var filename: String {
return self.name!
}
override init() {
}
override func isEqual(_ object: Any?) -> Bool {
if let obj = object as? FileProviderItem {
if self.itemIdentifier == obj.itemIdentifier {
return true
}
}
return false
}
var capabilities: NSFileProviderItemCapabilities {
return .allowsAll
}
}
为了FileProviderExtension
class FileProviderExtension: NSFileProviderExtension {
override func item(for identifier: NSFileProviderItemIdentifier) throws -> NSFileProviderItem {
// resolve the given identifier to a record in the model
// db = Array of NSFileProviderItem
for i in db {
if i.itemIdentifier.rawValue == identifier.rawValue {
return i
}
}
// TODO: implement the actual lookup
throw NSError(domain: NSCocoaErrorDomain, code: NSNotFound, userInfo:[:])
}
override func importDocument(at fileURL: URL, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
print("importDocument :- \(fileURL) parentItemIdentifier = \(parentItemIdentifier)")
completionHandler(nil, nil)
}
override func reparentItem(withIdentifier itemIdentifier: NSFileProviderItemIdentifier, toParentItemWithIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, newName: String?, completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) {
print("reparentItem :- \(itemIdentifier) parentItemIdentifier = \(parentItemIdentifier) newName = \(String(describing: newName))")
guard let item = try? item(for: itemIdentifier) as? FileProviderItem else {
completionHandler(nil, NSFileProviderError(.noSuchItem))
return
}
item?.pid = NSFileProviderItemIdentifier(rawValue: parentItemIdentifier.rawValue)
//item?.name = newName
completionHandler(item, nil)
}
}