0

I'm trying to implement Push-Notifications with this tutorial. Chat with PubNub works perfectly. I can also send and receive Push-Notifications with this script, but only with the development-certificate, so I submitted this to PubNub. (does anybody know why? I've created both Certificates for my App) When I open the App, I receive the Message with all Keys like I see it in the DebugConsole:

{ "message": "Asdas",
  "pn_apns": {
    "aps": {
      "alert": "To Apple and PN Native devices!"
    }
  },
  "senderId": "mySenderId",
  "receiverId": "myReceiverId"
}

I'll show all the steps I think are relevant for Push-Notifications, so please say if I forgot something or I did something wrong.

didFinishLaunching

UIUserNotificationType types = (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"pub-key" subscribeKey:@"sub-key"];
self.client = [PubNub clientWithConfiguration:configuration];
[self.client addListener:self];
[self.client subscribeToChannels:@"myChannelId" withPresence:NO];

didRegisterForRemoteNotificationsWithDeviceToken

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

send a PubNub-Chat Message

NSDictionary * dict = @{@"aps": @{@"alert":@"To Apple and PN Native devices!"}};
[self.client publish:@{@"message" : @"Hello!", @"senderId" : @"abc123", @"receiverId" : @"abc124"} toChannel:@"myChannel" mobilePushPayload:dict withCompletion:^(PNPublishStatus *status) {}];
Stephan Boner
  • 733
  • 1
  • 6
  • 27

2 Answers2

2

I was too stupid to subscribe for the right Channel. At the didRegisterForRemoteNotificationsWithDeviceToken you should use your unique Channel ID, instead of @"apns"...

Thanks for your Help

Stephan Boner
  • 733
  • 1
  • 6
  • 27
1

Dev and prod pushes aren't interchangeable. Make sure you have not broken the

"Push Rule of Three".

There are two sets of triplets:

a) Prod app - Prod gateway - Prod certificate
b) Dev app - Dev gateway - Dev certificate
You can't mix and match these together, if you have any combination that isn't either 3 Production things or 3 Dev things then the push won't work. This is the "Push Rule of Three".

This is the prod gateway:

ssl://gateway.push.apple.com:2195

And this is the dev gateway:

ssl://gateway.sandbox.push.apple.com:2195

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • Ok, thank you. I uploaded now the dev-cert to PubNub and use also the Dev-App (launched with Xcode), but it doesn't work... – Stephan Boner May 04 '16 at 16:21
  • How are you setting the push token on the server? The push token is different between prod and dev and it can change anyway. If you have an incorrect or old one then pushes won't work. – Gruntcakes May 04 '16 at 16:23
  • I set the Push-Token on the Server in didRegisterForRemote.... With the call self.client addPushNotifications... – Stephan Boner May 05 '16 at 09:20
  • I've got a bit confused with what you are trying to achieve. In your original question you said you could get pushes to work with the script but only with development certs. Then in your comment above you said you've uploaded the dev certs to pub nub. If it is working with dev then why are you uploading dev stuff? I thought the original question was you want to get it to work with prod? Anyway double check you are using either the dev certificate with the dev app build with the apple sandbox with a dev token or a prod cert with the prod app build with the apple non-sandbox with a prod token. – Gruntcakes May 05 '16 at 15:51
  • Sorry for the confusion. I can send Push-Notifications with this script, but just in dev-mode. PubNub doesn't work, neither in dev or in prod mode. – Stephan Boner May 05 '16 at 22:48