2

标题怎么说,当我打开一个 URL 时,我的 Share 扩展程序崩溃了。
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 {

                    }
                })
            }
        }
    }

}
4

0 回答 0