实现 iOS 推送通知(服务器端)

发布于 2024-12-03 04:26:59 字数 101 浏览 1 评论 0原文

我们希望能够向所有 iPhone 用户推送简单的短信。为此,我们显然需要创建一个服务器端代码来存储设备令牌并在必要时推送消息。有这样做的好例子吗? (谈论服务器代码)

谢谢

We want to be able to push simple text messages to ALL our iphone users. For that we obviously need to create a server side code that stores the device tokens and pushes the messages whenever necessary. Is there any good example on doing this? (Talking about the server code)

Thanks

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

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

发布评论

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

评论(3

沧笙踏歌 2024-12-10 04:26:59

如果您想自己托管,请查看 easyAPNS,或者访问 Urban Airship 如果您同意托管服务(他们有大量文档)

另一个不错的信息网站是 Ray Wenderlich 的网站,该网站托管了一个由两部分组成的教程:

  • <一href="http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12" rel="noreferrer">Apple 推送通知服务教程:第 1/2 部分
  • < a href="http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2" rel="noreferrer">Apple 推送通知服务教程:部分2/2

Have a look at easyAPNS if you want to host it yourself, or visit Urban Airship if you are ok with a hosting service (they have an extensive set of documentation)

Another good site for info is Ray Wenderlich's site which hosts a 2 part tutorial:

一袭白衣梦中忆 2024-12-10 04:26:59
  // Push Notification code for IPHONE in PHP 
  $deviceToken = $users_rows['gcm_regid'];
    $passphrase = 'pass1234';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'DrinksterDevelopment.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

    $fp = stream_socket_client(
        'ssl://gateway.sandbox.push.apple.com:2195', $err,
        $errstr, 120, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

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

    echo 'Connected to APNS' . PHP_EOL;

    $body['aps'] = array(
       // 'alert' => $_GET["message"].'#'.$_GET["type"].'#'.$_GET["deal_id"],
       'alert' => $_GET["message"],
        'sound' => 'default'
        );
    $body['other'] = $_GET["type"].'#'.$_GET["deal_id"];

    $payload = json_encode($body);
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    $result_iphone = fwrite($fp, $msg, strlen($msg));

    if (!$result_iphone)
        $msg_iphone = 'Message not delivered' . PHP_EOL;

    else
        $msg_iphone = 'Message successfully delivered' . PHP_EOL;

     mail('[email protected]', 'IOSPushMsgStatus', $msg_iphone);
     fclose($fp);
    } //if($users_rows['Platform'] == 'Web' OR $users_rows['Platform'] == 'Android')
  // Push Notification code for IPHONE in PHP 
  $deviceToken = $users_rows['gcm_regid'];
    $passphrase = 'pass1234';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'DrinksterDevelopment.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

    $fp = stream_socket_client(
        'ssl://gateway.sandbox.push.apple.com:2195', $err,
        $errstr, 120, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

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

    echo 'Connected to APNS' . PHP_EOL;

    $body['aps'] = array(
       // 'alert' => $_GET["message"].'#'.$_GET["type"].'#'.$_GET["deal_id"],
       'alert' => $_GET["message"],
        'sound' => 'default'
        );
    $body['other'] = $_GET["type"].'#'.$_GET["deal_id"];

    $payload = json_encode($body);
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    $result_iphone = fwrite($fp, $msg, strlen($msg));

    if (!$result_iphone)
        $msg_iphone = 'Message not delivered' . PHP_EOL;

    else
        $msg_iphone = 'Message successfully delivered' . PHP_EOL;

     mail('[email protected]', 'IOSPushMsgStatus', $msg_iphone);
     fclose($fp);
    } //if($users_rows['Platform'] == 'Web' OR $users_rows['Platform'] == 'Android')
帅气称霸 2024-12-10 04:26:59

我还建议使用外部服务,例如 Urban Airship 或 PushApps
我更熟悉最后一个,我可以告诉你,除了“常规”推送通知消息之外,你还可以通过分段、位置甚至调度通知来获取消息。起初,这对您来说可能不是一个关键功能,但随着您的用户群的增长,您会发现这些功能有多么重要。

I also recommend using an external service for that such as Urban Airship or PushApps.
I more familiar with the last, and I can tell you that besides of "regular" push notifications messages, you also get messaging by segmentation, location or even scheduling notification. It may not seem like a critical features for you at first, but as your user base grow, you'll see how important those features are.

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