Ios Swift,共享扩展名:NSItemProvider loadItem不工作
我有一个共享扩展,允许用户向应用程序添加图片 一切正常,但NSItemProvider.loadItem不工作 这是我在SLComposeServiceViewController中的代码:Ios Swift,共享扩展名:NSItemProvider loadItem不工作,ios,swift,xcode,Ios,Swift,Xcode,我有一个共享扩展,允许用户向应用程序添加图片 一切正常,但NSItemProvider.loadItem不工作 这是我在SLComposeServiceViewController中的代码: override func viewDidLoad() { let content = extensionContext!.inputItems[0] as! NSExtensionItem for attachment in content.attachments as! [NSIte
override func viewDidLoad() {
let content = extensionContext!.inputItems[0] as! NSExtensionItem
for attachment in content.attachments as! [NSItemProvider] {
let identifier = kUTTypeJPEG as String
let hasItemConforming = attachment.hasItemConformingToTypeIdentifier(identifier)
print("LOG : \(hasItemConforming)") // print True ! so item has conforming
if hasItemConforming {
attachment.loadItem(forTypeIdentifier: identifier , options: nil, completionHandler: { (coding:NSSecureCoding?, error:Error!) in
// this func not works and prints nothing
print("LOG : Loaded") // print nothing
print("LOG : error : \(error)") // print nothing
print("LOG : secureCoding : \(coding == nil)") // print nothing
})
}
}
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}
放置
在attachment.loadItem()而不是viewDidLoad()的completionHandler末尾,如下所示:
是否抛出错误?@Dopapp否,无happens@DopappisActive是什么意思?如果您是指hasItemConformingToTypeIdentifier,则返回true
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
attachment.loadItem(forTypeIdentifier: identifier , options: nil, completionHandler: {
data, error in
// Your code here
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
})