[英]iOS push notification localization not working
I am trying to build iOS push notification server that support localization. 我正在尝试构建支持本地化的iOS推送通知服务器。 I add to my ios project the message string to my localization and check it using
NSLocalizedString
. 我将消息字符串添加到我的ios项目中,并使用
NSLocalizedString
对其进行检查。
I am use this code: 我正在使用此代码:
<?PHP
if(isset($_GET['message']) && isset($_GET['sender']) ){
$deviceToken="5cca98f1 4e20c5e4 5267d4da 23437439 81959bd0 b75b7573 42a2f9d7 ceed8f0f";
$message = stripslashes($_GET['message']);
$sender = stripslashes($_GET['sender']);
$payload = '{
"aps":{
"alert":{
"loc-key":"'.$message.'",
"loc-args":["'.$sender.'"]
},
"badge":1,
"sound":"bingbong.aiff"
}
}';
print $payload;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'password');
$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 "Notifications sent!";
}
$devArray = array();
array_push($devArray,$deviceToken);
foreach($devArray as $deviceToken){
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack ("n",strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
}
fclose($fp);
print "This is the Device Token Sent Each Time".strlen($msg)."\n";
}
But no notification was sent to the device. 但是没有通知发送到设备。 When I tried without localization and send the message with this payload:
当我尝试不进行本地化并使用此有效负载发送消息时:
$payload = '{
"aps":{
"alert":"'.$message.'",
"badge":1,
"sound":"bingbong.aiff"
}
}';
The device received the notification. 设备收到通知。
I use this link of apple. 我使用这个苹果链接 。
What i am doing wrong? 我做错了什么?
It seems like you are missing , fixed code: 似乎您缺少固定的代码:
$payload = '{
"aps" :
{
"alert" :{
"loc-key":"'.$message.'",
"loc-args":["'.$sender.'"]
},//<=================
"badge" : 1,
"sound" : "bingbong.aiff"
}
}';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.