Debug push notification messages
This guide shows you how to diagnose why a push sent through Mobile Push Notifications isn't reaching a device. You do that by reading the errors FCM and APNs return to PubNub's mobile push gateway. Before you start, confirm:
- Your publish and subscribe key pair has Mobile Push configured.
- Your app is set up correctly in your iOS or Android developer account.
- Your test payload contains the required push payload keys, such as
pn_apnsorpn_fcm.
Subscribe to the -pndebug companion channel, then publish the test message to the original channel. For continuous monitoring, forward push errors to your endpoint instead. To check whether a specific device token is still registered, see Check push device registration. To check whether an FCM payload uses the correct data or notification keys, see Check the FCM payload. To rule out PubNub entirely, see Test mobile push notifications externally.
Publish to the debug channel
-
Go to the PubNub Debug Console and subscribe to the channel named
<your-channel>-pndebug. If you publish tofoo, subscribe tofoo-pndebug. -
Add
"pn_debug": trueto your message payload, at the top level, as a sibling ofpn_fcmandpn_apns, not nested inside either of them:
show all 26 lines1{
2 "pn_debug": true,
3 "pn_fcm": {
4 "data": {
5 "message": "hello"
6 }
7 },
8 "pn_apns": {
9 "aps": {
10 "alert": "hello"
11 },
12 "pn_push": [
13 {
14 "push_type": "alert",
15 "auth_method": "token", -
Publish the message to channel
foo(notfoo-pndebug). Publish from your client, your server, or the Debug Console itself. Debug messages arrive onfoo-pndebugalmost immediately.
Read the debug channel output
Check the message count first. A successful delivery reports how many registered devices received the push on each provider:
1Devices found for push notification apns: 2 fcm
If a device or the whole push failed, look for an error message instead. These are examples of the responses FCM and APNs send back to PubNub's mobile push gateway:
1fcm Error: InvalidRegistration Devices: null
2fcm WARNING error: NotRegistered, sub_key: sub-c-..., channel: my_channel, reg_id: APA91bHRRxfHHB_T0AVojoJx..., timetoken: 14567269547473296
3apns INFO Certificate for sub-c-... valid (expiration: Sep 14 08:58:26 2016 GMT)
4apns ERROR Error on APNs send for subkey sub-c-... / channel gone_fishing / device 2a0a6234ffdb85df6624cf0546...: invalid token
If the publish call itself returns HTTP 400 Bad Request, read the text description in the response body. Common causes are an invalid type argument, a missing channels value, or an invalid device token.
Related tasks
- Check push device registration. Confirm whether a device token is still registered on the channels you expect.
- Forward push errors and device removals to your endpoint. Send push errors and device-removal events to your endpoint.
- Check the FCM payload. Confirm your FCM message uses the correct
dataornotificationkeys. - Test mobile push notifications externally. Send directly to FCM or APNs to rule out PubNub.
- Send push notifications on iOS. Configure APNs credentials and register a device.
- Send push notifications on Android. Configure FCM credentials and register a device.
- Mobile push notifications. How Mobile Push Notifications bridges pub/sub with APNs and FCM.
- API limits. Push credential and payload size limits.