我打开URL时,iOS Swift Share Extension崩溃了

时间:2016-11-19 21:10:04

标签: ios swift xcode openurl share-extension

标题如何说明,当我打开网址时,我的共享扩展程序崩溃了 Xcode说:Thread 3: EXC_BAD_ACCESS (code=1, address=0x10)
我已经尝试过其他url方案,结果是一样的。

这是我的代码:

import UIKit
import MobileCoreServices

class ShareViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let content = extensionContext!.inputItems[0] as! NSExtensionItem
        let text = kUTTypeText as String

        for attachment in content.attachments as! [NSItemProvider] {
            if attachment.hasItemConformingToTypeIdentifier(text) {
                attachment.loadItem(forTypeIdentifier: text, options: nil, completionHandler: { (data, error) in
                    if error == nil {
                        let url = data as! URL

                        print(url)

                        print("mSwift://?\(url.absoluteString)")

                        let mSwift = URL(string: "mSwift://?\(url.absoluteString)")
                        self.extensionContext!.open(mSwift!,  completionHandler: nil) // Crash here

                    }else {

                    }
                })
            }
        }
    }

}

0 个答案:

没有答案