IPhone : iOS push notification localization not working

on Thursday, March 26, 2015

I am trying to build iOS push notification server that support localization. I add to my ios project the message string to my localization and check it using 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;
// print "sending message :" . $payload . "n";
$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 msg with this payload:



$payload = '{
"aps" :

{ "alert" : "'.$message.'",
"badge" : 1,
"sound" : "bingbong.aiff"
}
}';


the device received the notification! i use this link of apple: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW20


What i am doing wrong?


0 comments:

Post a Comment