【发布时间】:2017-03-11 15:35:02
【问题描述】:
我正在尝试通过单击按钮从消息扩展中打开我的母亲应用程序。我在我的扩展中使用了这个代码:
@IBAction func open(_ sender: UIButton) {
let url = URL(string: "swiftexamples://")
self.extensionContext?.open(url!, completionHandler: {(succes) in })
}
当我的母亲应用程序正在运行并在后台运行时,一切正常,但是当我想打开已关闭的应用程序时,它崩溃了。没有崩溃日志,我有类似的情况 iOS app crashes when first opened by URL Scheme 。 我很确定我必须向应用程序委托添加一些内容。 我找到了函数应用程序(_:open:options:)。问题是,我现在不知道如何实现“选项”部分。我写了这个:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let url = launchOptions?[UIApplicationLaunchOptionsKey.url] as? NSURL
let sourceApp = launchOptions?[UIApplicationLaunchOptionsKey.sourceApplication] as? String
let annotation = launchOptions?[UIApplicationLaunchOptionsKey.annotation] as? AnyObject
self.application(application, open: url, options:[sourceApp: String, annotation:AnyObject] )
return true
}
我还听说过通用链接,它们具有与 url 方案相似的能力。是否可以使用通用链接来实现我想要的?
【问题讨论】:
标签: ios swift swift3 imessage imessage-extension