如何知道所有设备令牌以循环发送推送通知(APNS)? [英] How to know all devices tokens to send push notification (APNS) in a loop?

查看:28
本文介绍了如何知道所有设备令牌以循环发送推送通知(APNS)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 php 代码发送给所有下载了我的 iPhone 应用程序的令牌.你能告诉我如何发送到多个设备以及如何进入设备令牌循环吗?

I'm trying to use a php code to send to all tokens who downloaded my iPhone application. Could you tell me how to send to multiple devices and how to get into a loop of devices tokens?

这是我的代码:

<?php

$deviceToken = ''; // HERE I CAN SEND TO ONE DEVICE

// Passphrase for the private key (ck.pem file)
// $pass = '';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'MY NOTIFICATION BODY';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];

// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);

if ($badge)
    $body['aps']['badge'] = $badge;
if ($sound)
    $body['aps']['sound'] = $sound;
/* End of Configurable Items */

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
// assume the private key passphase was removed.
// stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60,STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
}
else {
print "Connection OK\n";
}

$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) .      pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);

?>

推荐答案

我写了一个关于推送通知的教程.我建议你阅读它,这样你会更好地理解你应该做什么:http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

I wrote a tutorial on push notifications. I suggest you read it so you will better understand what you're supposed to do: http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

这篇关于如何知道所有设备令牌以循环发送推送通知(APNS)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆