環境
- Xcode Version 12.3 (12C33)
- macOS Catalina 10.15.7
- Firebase/Messaging 7.1.0
- Firebase Cloud Messaging によるリモート通知受信環境を構築済み
目的
- OSのバージョンごとに通知をタップして起動した際の挙動を確認したい
実現方法
- プロジェクトの TARGET > Signing & Capabilities から Bundle Identifier を確認
- 以下のようなファイルを作成し拡張子を「.apns」とし保存
- 起動中のシミュレータにドラッグアンドドロップ
test.apns
{
"Simulator Target Bundle": "(アプリのバンドルID)",
"aps": {
"alert": {
"title": "通知テストタイトル",
"body": "通知テストメッセージ"
}
}
}
結果
注意点
-
func application(_ application:didReceiveRemoteNotification userInfo:fetchCompletionHandler completionHandler:)
が呼ばれない-
FIRMessagingRemoteNotificationsProxy
で Method Swizzling している影響? - このためサイレントPUSH通知での画面更新等は確認できなかった
-
- FirebaseCloudMessaging 利用中・シミュレータ上で通知関連メソッドが呼び出されるかどうかは以下のとおり
メソッド | 呼び出されるか |
---|---|
func application(_ application:didFinishLaunchingWithOptions launchOptions:) -> Bool | ○(launchOptionsに通知データが含まれる) |
func application(_ application:didReceiveRemoteNotification userInfo:fetchCompletionHandler completionHandler:) | × |
func userNotificationCenter(_ center:willPresent notification:withCompletionHandler completionHandler:) | ○ |
func userNotificationCenter(_ center:didReceive response:withCompletionHandler completionHandler:) | ○ |