简体   繁体   English

Apple Push Notification未提供

[英]Apple Push Notification is not delivered

I know it's a little bit flooded with Apple's Push Notification Service (APNs) issues all over StackOverflow so I actually did a lot of researches before coming up my question. 我知道Apple的推送通知服务(APNs)问题有点充斥着StackOverflow,所以在提出我的问题之前,我实际上做了很多研究。

Basically, I have followed the apns-php's CertificateCreation , some tutorial like on mobiforge , and some from Matthijs Hollemans . 基本上,我遵循了apns-php的CertificateCreation ,一些像mobiforge的教程,还有一些来自Matthijs Hollemans Still, I can't get any notification posted onto my iPad 2. 不过,我无法在iPad 2上发布任何通知。

Basically these are the steps I have done: 基本上这些是我所做的步骤:

  1. I followed the CertificateCreation tutorial, I came out with server_certificates_bundle_sandbox.pem , entrust_root_certification_authority.pem . 我遵循了CertificateCreation教程,我推出了server_certificates_bundle_sandbox.pementrust_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. 按照mobiforge博客中指定的教程,我成功创建了App ID,配置文件并将它们很好地链接在一起。

    • Description: APNTest 描述: APNTest
    • Bundle Seed ID: Use Team ID 捆绑种子ID: 使用团队ID
    • Bundle Identifier: com.learn.APN 捆绑标识符: 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. 然后我使用我刚才用来获取证书的相同证书请求启用开发推送SSL证书(仅限现在),然后下载并将其安装到我的钥匙串中。

  4. I downloaded my provisioning profile in .mobileprovision file and loaded it into Xcode's Organizer under my iPad 2 device. 我在.mobileprovision文件中下载了我的配置文件,并将其加载到我的iPad 2设备下的Xcode的Organizer中。

  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 目标>信息>构建标识符: 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: 我在iPad 2上构建并运行应用程序。我的应用程序请求推送通知,在我批准之后,令牌ID出现在我的控制台中:

     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 . 我使用了apns-php ,更改了设备ID(原始64个hexa值),然后运行sample_push.php Script ran successfully, but my device is not receiving any notification 脚本运行成功,但我的设备没有收到任何通知

  9. Then I try to use the SimplePush.php . 然后我尝试使用SimplePush.php A "Message successfully delivered" appeared, but my iPad still doesn't receive any notification from APN 出现了“已成功发送消息”,但我的iPad仍未收到APN的任何通知

Question is, which steps have I done wrongly? 问题是,我做错了哪些步骤? I'm pretty newbie in this area, and it is actually a requirement for my project that the server need to send out messages to our own applications. 我在这方面很新手,实际上我的项目需要服务器需要向我们自己的应用程序发送消息。 We are aware of the third party softwares that send APN on behalf of you, but we would like to implement one ourselves. 我们知道代表您发送APN的第三方软件,但我们希望自己实施。

I also came across the " APN Feedback Service " and I written this (base on the SimplePush) but sadly it's empty. 我也遇到了“ APN反馈服务 ”,我写了这个(基于SimplePush),但遗憾的是它是空的。 What should I do now? 我现在应该怎么做?

<?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);

Note 注意

  1. I am aware of the differences between development/production certs. 我知道开发/生产证书之间的差异。
  2. iPad is not jailbroken, running iOS 5.0.1 iPad没有越狱,运行iOS 5.0.1
  3. Other App Store apps receives notifications normally 其他App Store应用程序通常会收到通知
  4. XCode 4.2.1, Lion 10.7.2 XCode 4.2.1,Lion 10.7.2

I hope I'm not duplicates any of the questions here.. ;) 我希望我不会重复这里的任何问题..;)

EDIT 编辑

When I run php simplepush.php then php feedback.php , I received a feedback with my device ID. 当我运行php simplepush.php然后php feedback.php ,我收到了我的设备ID的反馈。 My App is still in the iPad, so does it mean my device ID is wrong? 我的应用程序仍在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"
}

Thanks 谢谢

EDIT 编辑

After much struggling and redoing all the steps written by Matthijs Hollemans , I finally get it working. 经过多次努力和重做Matthijs Hollemans编写的所有步骤后,我终于开始工作了。 So the problem lies within the incorrect PEM file generated... hmm 所以问题在于生成的PEM文件不正确......嗯

I had similar problem, for me the key thing I didn't know is that the device token is different for dev and prod (for the same device) . 我有类似的问题,对我来说,我不知道的关键是设备令牌对于dev和prod(对于同一设备)是不同的

I was using the device token I got when testing in dev to test in prod. 我正在使用我在dev中测试时获得的设备令牌来测试产品。 This was working fine in dev, but when I switched to prod I kept the same device token in my python script (assuming, wrongfully, that the device token would be the same for the same device) but the actual device token registered in prod was different. 这是在开发中工作正常,但是当我切换到督促我保留了相同的设备令牌在我的python脚本(假设,错误地,该设备令牌是相同的,同一个装置),但在督促注册的实际设备令牌不同。

In practice this wouldn't happen as the device token is sent to the server, but when I was testing I was using hard coded device token as I didn't want to involve the server. 在实践中,这不会发生,因为设备令牌被发送到服务器,但是当我测试时,我使用的是硬编码设备令牌,因为我不想涉及服务器。

Hopefully this will save someone some frustration. 希望这会让某些人感到沮丧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM