I noticed there are a lot of guides on how to set up push notifications but I couldn’t find one explaining properly how to debug them.
It’s actually pretty easy and quick, I’ll assume you already have created and set up your APNS Certificate for development (if not, you can follow this guide from OneSignal).
- Download Pusher, an open source app to send push notifications
- In your AppDelegate file, be sure to have added the following function:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
- You will need to read the deviceToken variable, to do that you can use the following snippet:
let deviceTokenString = (deviceToken.description as NSString).stringByTrimmingCharactersInSet(characterSet).stringByReplacingOccurrencesOfString(“ “, withString: “”) as String
- Run your project on a device (simulators don’t support push notifications)
- Copy the printed out token in the debug console, if there is no token it means your push notification are not set up properly.
- Open the Pusher app downloaded in point 1:
- Select your push certificate and paste the token in the text box
- If the app is in foreground, tap the device’s home button
If you are debugging your project from XCode, you have to enable “Should use sandbox environment”.
You can now test with different payload and debug directly in XCode without the need for a notification service.