Apple 推送通知未发送

发布于 2024-12-27 17:05:58 字数 4727 浏览 1 评论 0原文

我知道 StackOverflow 上充斥着苹果的推送通知服务 (APN) 问题,所以在提出我的问题之前,我实际上做了很多研究。

基本上,我遵循了apns-php的CertificateCreation,一些教程,例如< a href="http://mobiforge.com/developing/story/programming-apple-push-notification-services" rel="noreferrer">mobiforge,以及一些来自 马蒂斯·霍尔曼斯。尽管如此,我还是无法在 iPad 2 上收到任何通知。

基本上,这些是我已完成的步骤:

  1. 我按照 CertificateCreation 教程,我推出了 server_certificates_bundle_sandbox.pementrust_root_certification_authority.pem
  2. 按照mobiforge博客中指定的教程,我成功了创建了应用程序 ID、配置文件并将它们很好地链接在一起。

    • 描述:APNTest
    • 捆绑种子 ID:使用团队 ID
    • 捆绑包标识符:com.learn.APN
  3. 然后我启用开发推送 SSL 证书(仅限目前)使用我刚才用来获取证书的相同证书请求,下载它并将其安装到我的钥匙串中。

  4. 我在 .mobileprovision 文件中下载了我的配置文件,并将其加载到我的 iPad 2 设备下的 Xcode 管理器中。

  5. 接下来,我仅使用以下代码创建一个简单的应用程序:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [[UIApplication shareApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
        // 应用程序启动后覆盖自定义点。
        返回是;
    }
    
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        NSLog(@"%@", deviceToken);
    }
    
    - (void)应用程序:(UIApplication *)应用程序 didFailToRegisterForRemoteNotificationsWithError:(NSError *)错误
    {
        NSLog(@"错误:%@",错误);
    }
    
  6. 然后配置构建参数:

    • 目标>信息>构建标识符:net.learn.APN
    • 目标>构建设置>代码签名身份> (我选择了刚刚安装的配置文件,它会自动为我的调试和发布选择相同的配置文件)
  7. 我在 iPad 2 上构建并运行该应用程序。我的应用程序请求推送通知并在我批准后,令牌 ID 出现在我的控制台中:

    2012-01-19 12:43:26.345 TestAPN[578:707] <3cb08612 9392996b 5332d2fc 5adce03d 994f8959 d7a2ac38 de7bed52 c8e0778e>
    
  8. 我使用了 apns-php,更改设备 ID(原始 64 个十六进制值),然后运行 ​​sample_push。 php.脚本成功运行,但我的设备未收到任何通知

  9. 然后我尝试使用 SimplePush.php。出现“消息已成功发送”,但我的 iPad 仍然没有收到 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 文件......嗯

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.

Basically, I have followed the apns-php's CertificateCreation, some tutorial like on mobiforge, and some from Matthijs Hollemans. Still, I can't get any notification posted onto my 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.
  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

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.

I also came across the "APN Feedback Service" and I written this (base on the SimplePush) but sadly it's empty. 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
  3. Other App Store apps receives notifications normally
  4. 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. My App is still in the iPad, so does it mean my device ID is wrong?

[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. So the problem lies within the incorrect PEM file generated... hmm

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

闻呓 2025-01-03 17:05:58

我遇到了类似的问题,对我来说,我不知道的关键是开发和生产的设备令牌不同(对于同一设备)

我使用在开发中测试时获得的设备令牌在产品中进行测试。这在开发中工作得很好,但是当我切换到产品时,我在 python 脚本中保留了相同的设备令牌(错误地假设同一设备的设备令牌是相同的),但在产品中注册的实际设备令牌是不同的。

实际上,当设备令牌发送到服务器时,这种情况不会发生,但当我测试时,我使用硬编码设备令牌,因为我不想涉及服务器。

希望这能减轻一些人的挫败感。

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).

I was using the device token I got when testing in dev to test in prod. 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文