LoginSignup
6
5

More than 3 years have passed since last update.

ユニバーサルリンク(Universal link)でアプリを開いてもAppDelegateのapplicationが呼ばれなくなった時の対処法(Swift5)

Posted at

これまで普通にできていたAppDelegateでのユニバーサルリンクのハンドリングが突然できなくなり、その時参考になる記事があまりなかったためその忘備録として。

ユニバーサルリンクからアプリを開いた際にAppDelegateの以下のメソッドでハンドリング処理をしていました

AppDelegate.swift

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        guard userActivity.activityType == NSUserActivityTypeBrowsingWeb else { return false }
        guard let url = userActivity.webpageURL else { return false }
        let handle = handleUniversalLink(URL: url)
        return handle
}

突然上記のメソッドが呼ばれなくなった原因としてパッと思いつくものがSwift5のバージョンアップしかなかったため、色々調べましたが最終的に以下のように修正したところ再びメソッドが呼ばれ、ハンドリングできるようになりました。

AppDelegate.swift

func application(_ application: UIApplication, continue continueUserActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        guard continueUserActivity.activityType == NSUserActivityTypeBrowsingWeb else { return false }
        guard let url = continueUserActivity.webpageURL else { return false }
        let handle = handleUniversalLink(URL: url)
        return handle
}

参考資料

こちらの記事が非常に参考になりました

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5