我有一个分享扩展,允许用户添加图片到应用程序,
一切都很好,但NSItemProvider .loadItem不工作
这是我在SLComposeServiceViewController中的代码:
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)
}发布于 2018-02-23 18:09:13
地点
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil) 在attachment.loadItem()而不是viewDidLoad()的completionHandler末尾,如下所示:
attachment.loadItem(forTypeIdentifier: identifier , options: nil, completionHandler: {
data, error in
// Your code here
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
})https://stackoverflow.com/questions/41856578
复制相似问题