Apple Push Notification Service已连接,但未收到任何通知

达拉斯凯利

在过去的一周里,我一直在努力地尝试着完成这项工作。我刚刚从头开始,并记录了我所做的一切,但仍然无法正常工作。这是我已采取的步骤:

1)使用新的捆绑包ID创建一个新的应用程序ID标识符(旧的ID没有推送通知)

a) made sure push notifications were added to the app id and proceeded to the last step, this resulted in an app id with push notifications in the ‘configurable’ state.

b) I then went to edit the app id and saw that i could create a new production or development certificate so i did both using the steps listed

2)创建了两个新的配置文件,一个用于开发,一个用于生产,都使用新的捆绑包ID

3)将新的配置文件导入Xcode,并确保这些文件是在构建设置中选择的配置文件

4)使用钥匙串创建.p12文件,并导出.cer文件以进行开发和生产

5)使用以下命令从.p12文件创建.pem文件:

openssl pkcs12 -in VX-Mobile-Dev.p12 -out apns-dev.pem -nodes -clcerts

openssl pkcs12 -in VX-Mobile-Prod.p12 -out apns-prod.pem -nodes -clcerts 

6)接下来创建了一个php脚本(我从另一个博客公然摘录了该脚本),该脚本是从我的一个虚拟机的命令行运行的。在与该文件相同的文件夹中,放入pans-prod.pem文件。这是该文件的内容

注意,对于设备令牌,我只是从Xcode运行应用程序,因为它已经成功连接到APNS服务器并获取设备令牌,该设备令牌已注销到控制台中,出于测试目的,我每次都将新令牌复制到文件中。

文件内容:

// set time limit to zero in order to avoid timeout
set_time_limit(0);

// charset header for output
header('content-type: text/html; charset: utf-8');

// this is the pass phrase you defined when creating the key
$passphrase = '{passphrase is hidden to you!}';

// you can post a variable to this string or edit the message here
if (!isset($_POST['msg'])) {
$_POST['msg'] = "Notification message here!";
}

// function for fixing Turkish characters
function tr_to_utf($text) {
    $text = trim($text);
    $search = array('Ü', 'Þ', 'Ð', 'Ç', 'Ý', 'Ö', 'ü', 'þ', 'ð', 'ç', 'ý', 'ö');
    $replace = array('Ãœ', 'Åž', 'Ğž', 'Ç', 'Ä°', 'Ö', 'ü', 'ÅŸ', 'ÄŸ', 'ç', 'ı', 'ö');
    $new_text = str_replace($search, $replace, $text);
    return $new_text;
}

// tr_to_utf function needed to fix the Turkish characters
$message = tr_to_utf($_POST['msg']);

// load your device ids to an array
$deviceIds = array(
'97c8c0a77e1380d052d17352e33b1f2224f082a3436ee90310cf88c7278329e7'
);

// this is where you can customize your notification
$payload = '{"aps":{"alert":"' . $message . '","sound":"default"}}';

$result = 'Start' . "\r\n";

////////////////////////////////////////////////////////////////////////////////
// start to create connection
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-prod.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

echo count($deviceIds) . " devices will receive notifications.\r\n";

foreach ($deviceIds as $item) {
    // wait for some time
    sleep(1);

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

    if (!$fp) {
        exit("Failed to connect: $err $errstr" . "\r\n");
    } else {
        echo 'Apple service is online. ' . "\r\n";
    }

    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $item) . pack('n', strlen($payload)) . $payload;

    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));

    if (!$result) {
        echo 'Undelivered message count: ' . $item . "\r\n";
    } else {
        echo("\r\nRESULT\r\n\r\n");
        var_dump($result);
        echo("\r\n\r\n");
        echo 'Delivered message count: ' . $item . "\r\n";
    }

    if ($fp) {
        fclose($fp);
        echo 'The connection has been closed by the client' . "\r\n";
    }
}

echo count($deviceIds) . " devices have received notifications.\r\n";

// set time limit back to a normal value
set_time_limit(30);

请帮忙。

达拉斯凯利

原来我快到了。唯一的问题是,我应该一直在使用沙盒端点。

ssl://gateway.sandbox.push.apple.com:2195

另外,作为对RJV Kumar的回应,一旦我开始使用它,我就同时使用了我的产品证书和我的开发证书,并且在两种情况下都可以使用。对我来说这似乎很可疑,但是无论我多么高兴它的工作。

[更新]

尽管本文中的步骤在技术上是正确的,但我了解到,如果您实际上希望能够发布新版本的应用程序,则不应创建新的应用程序ID。无需执行此操作,您只需将推送通知添加到当前的应用ID。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Apple Push Notification Service SSL(沙盒和生产)-尚未收到生产通知吗?

Apple Push Notification Service在生产中不起作用

Apple Push Notification Service服务器证书更新

解析来自Apple Push Notification的数据

对Apple Push Notification Services进行故障排除

尝试连接到Apple Push Notification Service时为什么会出现OpenSSL错误?

Apple Push Notification设置“远程通知”方法会覆盖其他方法

离线Apple Push Notification有效性

Apple Push Notification身份验证密钥(沙箱和生产)

如何在Mac上使用Apple Push Notification?

Apple Push Notification的App Delegate调用不显示ViewController

Mac更改后,Apple Push Notification不起作用

Mac for Application上的Apple Push Notification不在Appstore上

Apple Push Notification-最终用户试图充当CA

如何在带有Firebase的Xamarin和带有C#后端的Apple Push Notification中实现推送通知

如何在Apple Push Notification Service中设置声音?(它始终是默认值吗?)

批量发送Apple Push通知

Xcode免费配置:“ Apple Push Notification”功能仅适用于注册了Apple Developer Program的用户

我可以使用Apple Push Notification Service在不通知iOS 7用户的情况下使我的应用执行某些操作吗?

使用HttpClient,客户端证书和WinHttpHandler将HTTP / 2请求发送到Apple Push Notification Service会引发HttpRequestException

某些设备不接收Apple Push通知

使用APNS的Apple Push通知是否免费?

使用Push Notification Service Extension上传应用

Apple Push Notification服务必须合并新的根证书(AAACertificateServices)-APNS证书更新

使用Java和REST发送Apple Push Notification时出现问题

Apple Push Notification服务SSL(沙盒和生产)证书是否通用?

Apple Push Notification无法与临时版本一起使用,不能在开发中使用

如何使用Apple Push Notification P12证书文件通过代码设置ios平台?

Apple Push Notification到达后,无法通过滑动锁定屏幕(无密码)打开应用程序