推送通知IOS

时间:2011-04-19 12:42:26

标签: ios push-notification

因此。我安装了我的应用程序并在设置下显示我的应用程序已注册推送通知。我也得到了令牌,制作了pem文件,通过运行此命令检查它是否正确使用

  

apn stefanandrei $ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev.pem -debug -showcerts -CAfile server-ca-cert.pem

我正在使用这个PHP代码:

// send our authentification file
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem'); 

// open a connection to the sandbox server
$apnsConnection = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); 

// creating the notification message (256 Byte max)

// your device token here
$deviceToken = 'ba672efe 4d6b5b7b db89a08a e9b36da2 ada14b00 df2f0b36 3eb6515b 08d57879'; 

// your message goes here
$message = "Your push notification text goes here.";

// define a sound file if you want here
$sound = 'mySoundFile.caf'; //name of the sound file inside the XCode project.

// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
$badge = (int)$argv[2]; // a number which will be displayed over the apps icon
if ($badge)
{
  $body['aps']['badge'] = $badge;
}
if ($sound)
{
  $body['aps']['sound'] = $sound;
}
$payload = json_encode($body);

// remove blanks and pack it.
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
echo $msg;

// push the message through APNS
fwrite($apnsConnection, $msg); 

//close APNS connection
fclose($apnsConnection);
?>
<code>

问题是没有收到通知。我什么都收不到。我能做什么。

3 个答案:

答案 0 :(得分:0)

一种选择是使用enhanced notification format发送通知。执行此操作时,如果他们检测到任何错误,您将收到来自apns服务器的错误。这样你就可以了解最新情况。

答案 1 :(得分:0)

我们在iOS中通过两种方法发送推送通知:

  1. 使用.net后端:创建.p12文件;见How to send Push notification using .net backend

  2. Php后备: - 创建一个.pem文件;见Create “.pem” file for push mail (notification) for php backend

答案 2 :(得分:0)

删除Space表单设备令牌 ba672efe4d6b5b7bdb89a08ae9b36da2ada14b00 df2f0b363eb6515b08d57879 ,而不是尝试发送通知。