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

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

问题描述

我试图用一个PHP code发送给谁下载我的iPhone应用程序的所有令牌。你能告诉我如何发送到多个设备,以及如何进入设备令牌的循环?

这是我的code:

 < PHP$ deviceToken =''; //这里我可以发送给一台设备//密码短语私人密钥(ck.pem文件)
// $传球='';
//从获得的参数HTTP GET或命令行
$消息= $ _GET [消息]或$消息= $ ARGV [1]或$消息='我的通知机构;
$徽章=(int)的$ _ GET ['徽章']或$徽章=(int)的$ ARGV [2];
$声音= $ _GET ['声音']或$声音= $ ARGV [3];//构造通知有效载荷
$身体=阵列();
$身体['APS'] =阵列('警报'=> $消息);如果($徽章)
    $身体['APS'] ['徽章'] = $徽章;
如果($声音)
    $身体['APS'] ['音'] = $的声音;
/ *配置项目结束* /$ CTX = stream_context_create();
stream_context_set_option($ CTX,SSL,的local_cert',​​'APNS-dev.pem');
//假设去除私钥passphase。
// stream_context_set_option($ CTX,'SSL','密​​码',$通行证);
$计划生育=在stream_socket_client('SSL://gateway.sandbox.push.apple.com:2195',$犯错,$ errstr,60,STREAM_CLIENT_CONNECT,$ CTX);
如果(!$ FP){
PRINT无法连接$犯错$ errstrn
返回;
}
其他{
打印连接OK \\ N的;
}$有效载荷= json_en code($体);
$味精= CHR(0)。包(N,32)。包(H *',str_replace函数('','',$ deviceToken))。包(N的strlen($有效载荷))。 $有效载荷;
打印发送消息。 $有效载荷。 \\ n;
FWRITE($ FP,$味精);
FCLOSE($ FP);?>


解决方案

我写了一篇关于推送通知的教程。我建议你​​读它,所以你会更好的了解你应该做的:
<一href=\"http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12\">http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

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?

this is my code:

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

?>

解决方案

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天全站免登陆