【问题标题】:APNS: invalid token (8)APNS:无效令牌 (8)
【发布时间】:2013-05-06 06:35:55
【问题描述】:

我正在使用https://code.google.com/p/apns-php/ 提供的apns php 服务器。

我已经设置了推送通知证书,但我的代码在连接时仍然抛出错误。

这有什么问题?以下是我获取设备令牌的方式:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {

#if !TARGET_IPHONE_SIMULATOR

    // Prepare the Device Token for Registration (remove spaces and < >)
    NSString *deviceToken = [[[[devToken description]
                               stringByReplacingOccurrencesOfString:@"<"withString:@""]
                              stringByReplacingOccurrencesOfString:@">" withString:@""]
                             stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"%@", deviceToken);

#endif
}

这是我运行服务器时的错误:

Sat, 11 May 2013 13:37:53 -0700 ApnsPHP[18198]: INFO: Trying 
ssl://gateway.push.apple.com:2195...
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: STATUS: Sending message ID 1 [custom identifier: abc123] (1/3): 101 bytes.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: ERROR: Unable to send message ID 1: Invalid token (8).
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Disconnected.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Trying ssl://gateway.push.apple.com:2195...
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Sending messages queue, run #2: 1 message(s) left in queue.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: WARNING: Message ID 1 [custom identifier: abc123] has an unrecoverable error (8), removing from queue without retrying...
Sat, 11 May 2013 13:37:55 -0700 ApnsPHP[18198]: INFO: Disconnected.

【问题讨论】:

  • 您是否在此版本中使用了 Ad-Hoc 配置文件?否则生产证书将不起作用。
  • @edwardmp 是的,我认为这就是问题所在。

标签: php objective-c push-notification apple-push-notifications apns-php


【解决方案1】:

最可能的解释是您正在向生产 APNS 服务器发送带有沙盒设备令牌的推送通知。

您正在使用在沙盒环境中测试时由您的应用发送到您的服务器的旧设备令牌,或者您的应用仍使用开发配置文件进行签名,并且仍在接收来自的沙盒设备令牌APNS 服务。

我的回答假设您使用的是源自 APN 服务的设备令牌,而不是您自己创建的虚拟令牌。

我建议您检查配置文件以查看 aps 权利显示的值。我还建议您从任何旧设备令牌中清除您的数据库。

【讨论】:

  • hmm...现在我更改为沙盒并没有引发错误,但据我所知,我的设备仍然没有收到通知。
  • @JasonSilberman 你对沙盒做了什么改变?应用程序还是服务器?如果您在服务器上使用了错误的证书(使用沙盒推送证书连接到生产 APNS 服务器,反之亦然),设备将不会收到任何内容,服务器也不会收到任何错误响应。
  • 我正在使用沙箱网关和沙箱证书
  • aps 权利应该出现在您签署应用程序的配置文件中。你应该在你的个人资料中寻找&lt;aps-environment&gt;,看看它的值是development还是production
  • @Eran 你能检查我的问题,看看是否还有什么遗漏。一切似乎都是正确的,但我仍然收到同样的错误stackoverflow.com/questions/40152981/…
猜你喜欢
  • 1970-01-01
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-21
相关资源
最近更新 更多