DeeplinkでFirebase Cloud Messanging からViewControllerを起動

ここiOSにおけるカスタムURLとプッシュ通知からアプリ内へのリンク方法について説明します。

まずはxcodeにおいて、info.plistで、URL typesでURL identifierのstring(例えば com.mycompany.mymobileapp)を設定、そしてURL SchemeでItem のString(例えば mygameapp )を設定

プッシュ通知からURLをAppleDelegate内でパースします。

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

let urlHost : String = (url!.host as String?)!

let storyboard = UIStoryboard(name: “Main”, bundle: nil)

let resultVC = storyboard.instantiateViewController(withIdentifier: “ストーリーボードのID”) as! 起動したいUIViewコントローラ resultVC.コントローラへ渡す変数 = 変数
let rootViewController = self.window!.rootViewController as! UINavigationController rootViewController.pushViewController(resultVC, animated: true)

self.window?.makeKeyAndVisible()

これだけ!