apple-push-notificationspubnubapn

PubNub chat iOS app doesn't receive Push notification msg


I used PubNub service for chating in my app, and it could work well now, for: subscribe channel, publish msg to channel, receive msg... But not I want to receive push notification msg when one user send msg to a channel that user subscribeb. I configured APNS certificate in PubNub admin enter image description here

I tested my PEM file for Push service follow link

The push msg came. I added my device token to channels that I subscribed by

[self addPushNotificationsOnChannels:@[@"channel1", @"channel2"] withDevicePushToken:self.deviceToken andCompletion:^(PNAcknowledgmentStatus * _Nonnull status) {
    if (!status.error) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Token Chat" message:status.errorData.information delegate:@"Sent token OK" cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];

    }
    else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Token error" message:status.errorData.information delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];
    }
}];

And then, I double checked list channels that the deviceToken was be added again, the list channels are matched. But when I tried to send (publish) msg from chat (from user to user, user to channel), my device didn't receive any push msg.

I perhap miss some steps or something? Pls advise!


Solution

  • PubNub Mobile Push Notification Format

    As discussed in private support thread, your message:

    {"data":{"time":1523961017642,"text":"Hello"},"event":"dev-ecteam","sender":"DOAN-dev-ecteam"}
    

    ...does not include pn_apns. In order for PubNub to know that you want to send this as a push notification via APNS, you must include the message inside of pn_apns and APNS requires aps key (data key is required for Android).

    {
      "pn_gcm": {
       "data": {
        "time": 1523961017642,
        "text": "Hello"
       },
       "event": "dev-ecteam",
       "sender": "DOAN-dev-ecteam"
      },
      "pn_apns": {
       "aps": {
        "time": 1523961017642,
        "text": "Hello"
       },
       "event": "dev-ecteam",
       "sender": "DOAN-dev-ecteam"
      }
    }
    

    The entire message will be received by any subscribers that are actively subscribed, but only the contents of pn_gcm will be received by Android devices and contents of pn_apns will be received by iOS devices registered for push notifications on the channel.

    For more information on PubNub Mobile Push Notification, see: