1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Swift】XcodeのシミュレータでPush通知をタップした場合のテストを簡単にやりたい

1
Posted at

どういうことか

Push通知をタップするとAppDelegateの UNUserNotificationCenterDelegate が働くが、こちらの中身がちゃんと動いてるかなどを確認したい。
シミュレータでのチェックを想定している。実機でチェックする方法はここでは省く(手間がかかる方法しか見つからなかった)。

apnsファイルを作りましょう

Json形式でこんなものを作る。

test.apns
{
    "Simulator Target Bundle": "アプリのBundle Identifier",
    "aps":{
        "alert":"テストです",
        "sound":"default",
        "badge":1
    }
}

保存して .apns という拡張子で保存する。
作ったファイルをシミュレータにドラッグドロップすると通知が出てくるので、タップして動作を確認しよう。
ちなみに "badge" を100にするとアイコンに表示されるバッジ数は100になるけど届く通知は1つだけ。

参考

コマンドラインから送る方法もある。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?