Sirwin
Sirwin
Simulating remote push notifications in an iOS simulator

Simulating remote push notifications in an iOS simulator

By rizwanahmed | ohmyswift | 28 May 2021


Apple released Xcode 11.4 beta with tons of features. One of the notable features is simulating remote push notifications in simulators, which means that triggering remote notifications in simulators is now possible.

Requirements

Well, the requirements are quite simple. We will be needing the following,

  • Xcode 11.4 beta or above.
  • Bundle identifier of your app.
  • The device identifier of your currently active simulator.
  • Push notification payload.
  • Terminal.

How to find the device identifier of the simulator

You can find the simulator’s device identifier from Window -> Devices and Simulator -> Select the active simulator -> Copy the displayed identifier

How to generate push notification payload

The push notification payload is of the standard Apple format.

{"aps":{"alert":"I am a remote push notification","badge":1,"sound":"default"}}

Save the following JSON in the .apns format. (We will be saving the json in a file as notficationpayload.apns for the tutorial purpose. )

How to trigger remote push notifications in the simulator

  • Run the app in simulator using Xcode.
  • Open terminal.
  • Navigate to the folder where the payload file is present .
  • Execute the command with the format, xcrun simctl push <device-identifier> <your-bundle-id> notificationpayload.apns (Sample command - xcrun simctl push 3A3CE233-307D-463D-A1C6-F66B9C2C1445 com.sample.pushnotification notificationpayload.apns)

  • Hit enter.

That’s it! Notifications will start to appear on your simulator!

Simulating remote push notifications in a simulator

 

Enjoyed reading it? Feel free to share your comments below. Like this article? Share it with your friends! You can also follow me on twitter right here: https://twitter.com/rizwanasifahmed

App Showcase

We always want to give back to the community. So we decided that we will review some of the most amazing apps which we had used. Please download their apps and show them your support.

App name - Winya (iOS and iPad OS app)

free screen-sharing app that casts your screen to Twitch in HD. It will be useful for gamers to streaming their gameplay to Twitch. Ohmyswifters, download the app and show your support to them.

iOS, and iPadOS download link

 

 

This article was originally posted at https://ohmyswift.com/blog/2020/12/19/common-problems-and-workarounds-while-building-apps-using-apple-silicon/

How do you rate this article?

0


rizwanahmed
rizwanahmed

iOS developer. Writes about Swift and iOS development.


ohmyswift
ohmyswift

Weekly articles about Swift and iOS development.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.