gpt4 book ai didi

ios - 无法向 iOS 发送/接收 PubNub 推送通知

转载 作者:行者123 更新时间:2023-11-28 19:38:02 25 4
gpt4 key购买 nike

我正在尝试使用 this 实现推送通知教程。与 PubNub 聊天非常有效。我还可以使用 this 发送和接收推送通知脚本,但只有开发证书,所以我将其提交给了 PubNub。 (有人知道为什么吗?我已经为我的应用程序创建了两个证书)当我打开应用程序时,我收到了包含所有 key 的消息,就像我在 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) {}];

最佳答案

我太笨了,没有订阅正确的 channel 。在 didRegisterForRemoteNotificationsWithDeviceToken 中,您应该使用您唯一的 channel ID,而不是 @"apns"...

感谢您的帮助

关于ios - 无法向 iOS 发送/接收 PubNub 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37013797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com