Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift,共享扩展名:NSItemProvider loadItem不工作_Ios_Swift_Xcode - Fatal编程技术网

Ios Swift,共享扩展名:NSItemProvider loadItem不工作

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

我有一个共享扩展,允许用户向应用程序添加图片

一切正常,但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)
}
放置

在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) 
})