在iPhone中未获得推送通知

在iPhone中未获得推送通知,iphone,push-notification,apple-push-notifications,Iphone,Push Notification,Apple Push Notifications,我已经使用了下面的推送通知代码,它也给我成功连接到APNS消息的消息 交付。 我的iphoneuid也是正确的,但我仍然无法在Iphone中获取和通知。我以为Pem文件中有错误,但当我使用parse sever时,我已经收到了通知。我找不到什么问题,有人能帮我吗 <?php // Put your device token here (without spaces): $deviceToken = '8945fccefc3a11ea07e208238091595a688d2fa0

我已经使用了下面的推送通知代码,它也给我成功连接到APNS消息的消息 交付。 我的iphoneuid也是正确的,但我仍然无法在Iphone中获取和通知。我以为Pem文件中有错误,但当我使用parse sever时,我已经收到了通知。我找不到什么问题,有人能帮我吗

    <?php

// Put your device token here (without spaces):
$deviceToken = '8945fccefc3a11ea07e208238091595a688d2fa0';

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

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

////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

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

if (!$fp)
    exit("Failed to connect: $err $errstr" . 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);
?>

可能是您上载此php文件的服务器没有打开端口2195。我上载到两台服务器上,然后在localhost alsofrom localhost上尝试不工作?从你的终端?我是从现场收到的,我也收到了一条消息,但没有收到通知。