How to test push notification in Simulator
This is another article from push notification series, So far we have learnt through.
- How iOS push notification works?
How does iOS push notification work?
This article will explain, how the iOS push notification works in architecture level. This article is built for…
2. How to configure iOS app to receive push notification?
How to configure the iOS app to receive the push notification?
This article is the second part of the push notification series. If you haven’t seen what is the first part, it’s all…
3. How to generate authentication token/ push notification certificate to send push notification?
How to generate authentication token/Notification Certificate in AppStore connect for send push…
This is another article in push notification series. This article is going to explain how to generate the…
4. How to send push notification to real device without server configuration(for testing purposes)?
How to send notification to device without server configuration.
This article is another milestone article for the push notification series. This article is going to explain how send…
But, Is there any way to test the push notification in Simulator? Yes, Now we can test the push notification in Simulator as well. This article is going to explain to you how this can be done.
From the Xcode 11.4 onwards apple allows the developers to test the push notification in the simulator with two options. The details can be found in the Xcode 11.4 apple’s release notes
- By drag and dropping the APNS file
- By using the Xcode command line
Before starting, please make sure your app is ready to receive push notifications, if you want you can check out my previous article.
By drag and drop APNS file
Save this file in your project path which you created already or you can store this anywhere on your machine.
Wait what is Simulator Target Bundle 🤔? This object is used by Apple to verify which app(By checking and verifying by using the bundle Id) you are trying to send the push notification.
After saving the file, install the app in the simulator and enable the push notification permission.
Drag and drop the previously saved .apns file into the simulator, you will be able to see the notification 🥳.
By Using the Xcode Command Line
Create the .apns file in your project file or you can save it anywhere on your machine.
Open the terminal and navigate to the file which you created.
Execute this command and see you should be able to see the push notification on your simulator
xcrun simctl push <DeviceID> com.achsuthan.iOSPushNotificationSetup pushnotification.apns
But how to get the simulator’s DeviceID 🧐?.
In order to get the simulator device Id, In the Xcode Window -> Device and Simulator -> Select the simulator which you already installed the app -> Can get the device Id from the identifier.
Important points to take note of 📝
- The .apns file should have the JSON data format, we can’t have the last object with a comma(“,”)
- Simulator Target Bundle must be your app bundle Identifier
- If the simulator not receiving the push notification, make sure you have registered and configured push notification setup in Xcode properly and accept the permission request.
- And make sure your app is supporting the foreground push to receive.
We reached the end of the article, from this article we learned how we can send push notifications to the simulator for testing purposes in two different ways.
I hope you guys learned new stuff through this article as well. Let me know if you want me to improve or any questions feel free to add in the comments section. Btw don’t forget to give some claps 👏 which helps me to write more articles 😃.
Where to go from here, next article will be an advanced version of a push notification part 1 it’s all about UNAuthorizationOptions, checkout the article to explore about it.
Advanced version of push notification Part 1— UNAuthorizationOptions
This article is the advanced version of the push notification series. This article is going to cover mostly the…
Check out the GitHub project to get the latest code