Remote/Push Notification in iOS Simulator — In 10 Easy Steps
Awesome! Now you can test remote notifications in Simulator by using Xcode 11.4 or later & iOS 13.4 or later. You can add Remote Notifications to iOS Simulator in 10 easy steps.
I’m excited to start this, Let’s quickly dive in…
- Open Xcode — Create a new iOS app as shown.
2. Choose the product name, ‘PushNotificationTest’ or your own name, also interface as ‘Storyboard’ & language as ‘Swift’ as shown.
3. Select project & targets, tap on ‘Signing & capabilities’ then + Capability, filter results by typing ‘background’ and add Background Modes as shown.
4. Enable Remote Notifications in Background Modes.
Let’s start writing the code:
5. In AppDelegate, import UserNotifications & also add protocol UNUserNotificationCenterDelegate.
import UserNotifications
6. Add the method, registerForPushNotifications() as shown.
7. Run the app, you’d asked for permission of notifications, tap to allow it.
8. # PayLoad — Each notification your provider server sends to the Apple Push Notification service (APNs) includes a payload. You can consult Apple documentation here. Create a new TextEdit and add the following JSON and make sure you edit the bundle identifier as shown:
Note: You can add your app bundle identifier into the key: “Simulator Target Bundle”
Here is an example:
9. Save it to your local machine — any name you want and remember the location, we are going to need this throughout the course of testing. I save it as payload.apns
10. Drag and drop the payload.apns
on to your Simulator where your app is installed as shown:
Hurrah! There you go, you can see the awesome notification on iOS Simulator which helps debug your app instead of depending on the iOS Device for testing.