IOS推送通知不会从MDM服务器到达设备

时间:2013-01-11 05:06:31

标签: iphone ios push-notification

我正在研究移动设备管理系统,我的推送通知无效。我的代码是

//$apnsHost = 'gateway.push.apple.com';
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'PushCert.pem';

// Put your device token here (without spaces):
$deviceToken = 'my-device-token'; //I have replaced my actual token here

// Put your private key's passphrase here:
$passphrase = 'pushchat';

// Put your alert message here:
$message = 'My first push notification!';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $apnsCert);
//stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp)
    exit("Failed to connect: $error $errorString" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default'
    );

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered' . PHP_EOL;

// Close the connection to the server
fclose($fp);

我收到了“连接到APNS消息已成功发送”的消息。但通知并没有出现在iPhone设备上。我还应该检查什么以及解决方案是什么?我还检查了Iphone日志到配置实用程序,但是当我运行脚本时没有看到日志。

0 个答案:

没有答案