【问题标题】:Cannot send/receive PubNub Push-Notifications to iOS无法向 iOS 发送/接收 PubNub 推送通知
【发布时间】: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


    【解决方案1】:

    我太愚蠢了,无法订阅正确的频道。在 didRegisterForRemoteNotificationsWithDeviceToken 中,您应该使用您的唯一频道 ID,而不是 @"apns"...

    感谢您的帮助

    【讨论】:

      【解决方案2】:

      Dev 和 prod 推送不可互换。确保你没有破坏

      “三推规则”。

      有两组三元组:

      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

      【讨论】:

      • 好的,谢谢。我现在将 dev-cert 上传到 PubNub 并使用 Dev-App(使用 Xcode 启动),但它不起作用......
      • 如何在服务器上设置推送令牌? prod 和 dev 之间的推送令牌是不同的,无论如何它都可以更改。如果你有一个不正确或旧的,那么推送将不起作用。
      • 我在 didRegisterForRemote.... 中设置了服务器上的 Push-Token 调用 self.client addPushNotifications...
      • 我对你想要达到的目标有点困惑。在您最初的问题中,您说您可以推动使用脚本,但只能使用开发证书。然后在您上面的评论中,您说您已将开发证书上传到 pub nub。如果它正在与开发人员合作,那么您为什么要上传开发人员的东西?我认为最初的问题是你想让它与 prod 一起工作吗?无论如何,请仔细检查您是使用带有开发令牌的苹果沙箱构建的开发证书,还是带有带有产品令牌的苹果非沙箱的产品应用构建的产品证书。
      • 很抱歉给您带来了困惑。我可以用这个脚本发送推送通知,但只能在开发模式下。 PubNub 不起作用,无论是在开发模式下还是在生产模式下。
      猜你喜欢
      • 2016-08-22
      • 1970-01-01
      • 2018-04-22
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多