【发布时间】:2016-05-03 20:30:04
【问题描述】:
我正在尝试使用 this 教程实现推送通知。与 PubNub 聊天完美无缺。我也可以使用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-Chat 消息
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) {}];
【问题讨论】:
标签: ios objective-c push-notification apple-push-notifications pubnub