0

I've got this code set up in my AppDelegate's didFinishLaunchingWithOptions:

PNConfiguration *pnConfiguration = [PNConfiguration configurationWithPublishKey:publishKey
                                                                   subscribeKey:subscribeKey];
self.client = [PubNub clientWithConfiguration:pnConfiguration];

/* push notifications */
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];

As well as these two methods:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"deviceToken: %@", deviceToken);
    [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"DeviceToken"];

    [self.client addPushNotificationsOnChannels:@[@"apns"] withDevicePushToken:deviceToken andCompletion:^(PNAcknowledgmentStatus *status) {

    }];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"%s with error: %@", __PRETTY_FUNCTION__, error);
}

I've added the entitlement to my app ID, and uploaded the certificate to the PubNub console as described here

Here's my code for sending a push notification:

[self.client publish:nil toChannel:@"apns" mobilePushPayload: @{@"aps": @{@"alert":message}}
withCompletion:^(PNPublishStatus *status) {
    // Check whether request successfully completed or not.
    // if (status.isError) // Handle modification error.
    // Check 'category' property to find out possible issue because
    // of which request did fail. Request can be resent using: [status retry];
}];

However, no notification is displayed on my iPhone when publishing from the iOS simulator. Any idea why this is?

Erik
  • 2,500
  • 6
  • 28
  • 49
  • Can you follow the [PubNub mobile push troubleshooting guide here](https://www.pubnub.com/knowledge-base/discussion/1127/how-can-i-troubleshoot-my-push-notification-issues) and provide valuable data points from that if you still are unable to determine the issue? – Craig Conover May 23 '16 at 17:23
  • Did the troubleshooting guide help? – Craig Conover May 24 '16 at 15:17
  • @CraigConover still looking at it. Might be using Firebase as it looks like they also feature push notifications. Not sure what to go for yet – Erik May 24 '16 at 16:01
  • They do provide push notifications as does many other vendors but PubNub and Firebase are different on the realtime data streaming side. – Craig Conover May 24 '16 at 16:02

1 Answers1

0

Push Notifications don't work on simulator. You will need to test on a real device.

JoakimE
  • 1,820
  • 1
  • 21
  • 30
  • I'm listening for the notification on my real iPhone 5S, but sending it from a simulator. – Erik May 22 '16 at 14:35