无法 send/receive PubNub 推送通知到 iOS
Cannot send/receive PubNub Push-Notifications to iOS
我正在尝试使用 this tutorial. Chat with PubNub works perfectly. I can also send and receive Push-Notifications with this 脚本实现推送通知,但仅限于开发证书,所以我将其提交给了 PubNub。 (有人知道为什么吗?我已经为我的应用程序创建了两个证书)当我打开应用程序时,我收到了包含所有密钥的消息,就像我在 DebugConsole 中看到的那样:
{ "message": "Asdas",
"pn_apns": {
"aps": {
"alert": "To Apple and PN Native devices!"
}
},
"senderId": "mySenderId",
"receiverId": "myReceiverId"
}
我将展示我认为与推送通知相关的所有步骤,所以如果我忘记了什么或做错了什么,请告诉我。
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) { }];
发送 PubNub 聊天消息
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) {}];
Dev 和 prod 推送不可互换。确保你没有破坏
"Push Rule of Three".
有两组三胞胎:
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".
这是产品网关:
ssl://gateway.push.apple.com:2195
这是开发网关:
ssl://gateway.sandbox.push.apple.com:2195
我太笨了,没有订阅正确的频道。在 didRegisterForRemoteNotificationsWithDeviceToken 你应该使用你唯一的频道 ID,而不是 @"apns"
...
感谢您的帮助
我正在尝试使用 this tutorial. Chat with PubNub works perfectly. I can also send and receive Push-Notifications with this 脚本实现推送通知,但仅限于开发证书,所以我将其提交给了 PubNub。 (有人知道为什么吗?我已经为我的应用程序创建了两个证书)当我打开应用程序时,我收到了包含所有密钥的消息,就像我在 DebugConsole 中看到的那样:
{ "message": "Asdas",
"pn_apns": {
"aps": {
"alert": "To Apple and PN Native devices!"
}
},
"senderId": "mySenderId",
"receiverId": "myReceiverId"
}
我将展示我认为与推送通知相关的所有步骤,所以如果我忘记了什么或做错了什么,请告诉我。
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) { }];
发送 PubNub 聊天消息
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) {}];
Dev 和 prod 推送不可互换。确保你没有破坏
"Push Rule of Three".
有两组三胞胎:
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".
这是产品网关:
ssl://gateway.push.apple.com:2195
这是开发网关:
ssl://gateway.sandbox.push.apple.com:2195
我太笨了,没有订阅正确的频道。在 didRegisterForRemoteNotificationsWithDeviceToken 你应该使用你唯一的频道 ID,而不是 @"apns"
...
感谢您的帮助