Apple 文件应用程序通过文件提供程序扩展执行 "Move" 操作我的扩展显示禁用
Apple File Application perform "Move" action via file provider extension my extention display disable
在我的文件提供程序扩展中,我想在我的 NoteProvider 扩展中执行移动操作。
我可以通过任何文件夹上方的拖动操作移动任何文件,它可以正常工作但是当我尝试 "Move" 通过波纹管屏幕中的操作显示时,屏幕 2 显示和其他扩展已启用,但我的 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)
}
}
NoteProvider(FileProvider) .plist 文件图像
return NSFileProviderItem itemForIdentifier 方法中标识符 NSFileProviderRootContainerItemIdentifier 的实例。如果您 return 根标识符为 nil,应用程序将不会在移动操作中启用。
在我的文件提供程序扩展中,我想在我的 NoteProvider 扩展中执行移动操作。
我可以通过任何文件夹上方的拖动操作移动任何文件,它可以正常工作但是当我尝试 "Move" 通过波纹管屏幕中的操作显示时,屏幕 2 显示和其他扩展已启用,但我的 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)
}
}
NoteProvider(FileProvider) .plist 文件图像
return NSFileProviderItem itemForIdentifier 方法中标识符 NSFileProviderRootContainerItemIdentifier 的实例。如果您 return 根标识符为 nil,应用程序将不会在移动操作中启用。