苹果推送通知未发送成功

9
我知道StackOverflow上到处都是苹果推送通知服务(APNs)问题,所以在提出我的问题之前,我实际上进行了很多研究。
基本上,我已经按照apns-php的证书创建,一些教程如mobiforge上的教程,还有Matthijs Hollemans的教程去操作了。但是,我无法将任何通知发布到我的iPad 2上。
基本上,这些是我所做的步骤:
  1. I followed the CertificateCreation tutorial, I came out with server_certificates_bundle_sandbox.pem, entrust_root_certification_authority.pem.
  2. Followed the tutorial specified in mobiforge blog, I successfully created the App ID, provisioning profile and linked them together nicely.

    • Description: APNTest
    • Bundle Seed ID: Use Team ID
    • Bundle Identifier: com.learn.APN
  3. Then I enable the Development Push SSL Certificate (only for now) using the same certificate request I have used just now to get the certs, and I download it and install it into my keychain.

  4. I downloaded my provisioning profile in .mobileprovision file and loaded it into Xcode's Organizer under my iPad 2 device.

  5. Next I create a simple application with only these codes:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
        // Override point for customization after application launch.
        return YES;
    }
    
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        NSLog(@"%@", deviceToken);
    }
    
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
        NSLog(@"Error: %@", error);
    }
    
  6. Then I configure the build parameters:

    • Targets > Info > Build Identifier: net.learn.APN
    • Targets > Build Settings > Code Signing Identity > (I chose the provisioning profile I have installed just now, and it automatically selects the identical profiles for my Debug and Release)
  7. I build and run the application on my iPad 2. My application requesting for Push Notification and after I approved it, the Token ID appeared in my console:

    2012-01-19 12:43:26.345 TestAPN[578:707] <3cb08612 9392996b 5332d2fc 5adce03d 994f8959 d7a2ac38 de7bed52 c8e0778e>
    
  8. I used apns-php, changed the device ID (raw 64 hexa-values), then run the sample_push.php. Script ran successfully, but my device is not receiving any notification

  9. Then I try to use the SimplePush.php. A "Message successfully delivered" appeared, but my iPad still doesn't receive any notification from APN

问题是,我做错了哪些步骤?我在这个领域还是新手,我的项目实际上要求服务器向我们自己的应用程序发送消息。我们知道有第三方软件可以代表您发送APN,但我们想自己实现一个。
我还发现了“APN反馈服务”,我根据SimplePush写了这个(但不幸的是它是空的)。现在我该怎么办?
<?php
// Put your private key's passphrase here:
$passphrase = '';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'server_certificates_bundle_sandbox.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client(
        'ssl://feedback.sandbox.push.apple.com:2196', $err,
        $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
        exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

while (!feof($fp)) {
        $data = fgets($fp, 1024);
        var_dump(unpack("N1timestamp/n1length/H*devtoken", $data));
}
// Close the connection to the server
fclose($fp);

注意:
1.我知道开发/生产证书之间的差异。 2.iPad没有越狱,运行iOS 5.0.1 3.其他App Store应用程序可以正常接收通知。 4.XCode 4.2.1,Lion 10.7.2
我希望我没有重复这里的任何问题.. ;)
编辑:
当我运行php simplepush.php然后php feedback.php时,我收到了一个带有我的设备ID的反馈。我的应用程序仍然在iPad上,这是否意味着我的设备ID是错误的?
[root@ip-xx-xx-xx-xx SimplePush]# php feedback.php
Connected to APNS
array(3) {
  ["timestamp"]=>
  int(1326962028)
  ["length"]=>
  int(32)
  ["devtoken"]=>
  string(64) "3cb086129392996b5332d2fc5adce03d994f8959d7a2ac38de7bed52c8e0778e"
}

感谢。 编辑: 在经过Matthijs Hollemans所写的所有步骤的反复努力和重做后,我终于让它工作了。因此问题在于生成的PEM文件不正确...嗯。

我重置了所有内容并重新开始了http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12的每一步,现在推送通知正常工作... 嗯 - Lionel Chan
推送通知服务在过去几天中一直存在问题。苹果公司发送了一封电子邮件,建议重新生成您的配置文件。您可能已经受到影响。 - nevan king
谢谢。我通过仔细按照 raywenderlich.com 上的所有步骤解决了我的问题。我相信这与证书问题有关。无论如何,我已经解决了我的问题。我应该将我的答案发布上去吗?(基本上与页面相同) - Lionel Chan
你不妨把你的答案发出来,任何有帮助的东西都是好的。 - nevan king
很可能。我稍后会在这里发布我的步骤,以便其他需要的人可以使用;基本上与教程中的相同,只是基于XCode 4.2.1和新的苹果证书界面进行了一些修改。 - Lionel Chan
1个回答

16

我也曾遇到类似的问题,对我来说,关键是我不知道同一设备在开发和生产环境下的设备标识符是不同的

当我在开发环境下测试时获得的设备标识符,我在生产环境下使用它进行测试。在开发环境中这能正常工作,但当我切换到生产环境时,我在 Python 脚本中继续使用相同的设备标识符(错误地假定同一设备的设备标识符是相同的),但实际上在生产环境中注册的设备标识符是不同的。

实际情况下这种情况不会发生,因为设备标识符会发送给服务器,但当我进行测试时,由于不想涉及服务器,我使用硬编码的设备标识符。

希望这能够帮助到有需要的人。


但我还没有接触过生产证书。我怎么可能搞砸它呢?谢谢您的快速回复! - Lionel Chan
这是绝对正确的!生产模式下的设备令牌与开发模式下的不同。我已经苦思冥想了几个小时,试图找出问题所在,而这解决了我的问题。谢谢! - user376845
这个答案解决了我在客户问题和个人测试之间长时间困扰的头痛问题。我无法准确定位问题所在。我向您致敬!非常感谢。附言:我的问题甚至让我更改了后端用于生产/开发环境的.pem文件。 - Roy Jacobs

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接