6
3

More than 3 years have passed since last update.

【iOS】シミュレータでPUSH通知を表示する

Posted at

環境

  • Xcode Version 12.3 (12C33)
  • macOS Catalina 10.15.7
  • Firebase/Messaging 7.1.0
    • Firebase Cloud Messaging によるリモート通知受信環境を構築済み

目的

  • OSのバージョンごとに通知をタップして起動した際の挙動を確認したい

実現方法

  1. プロジェクトの TARGET > Signing & Capabilities から Bundle Identifier を確認
  2. 以下のようなファイルを作成し拡張子を「.apns」とし保存
  3. 起動中のシミュレータにドラッグアンドドロップ
test.apns
{
    "Simulator Target Bundle": "(アプリのバンドルID)",
    "aps": {
        "alert": {
            "title": "通知テストタイトル",
            "body": "通知テストメッセージ"
        }
    }
}

結果

Simulator Screen Shot - iPhone SE (iOS 14.2.2nd generation) - 2021-02-24 at 11.48.08.png

注意点

  • 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:)
6
3
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
3