0
推送通知在iOS 8中未收到。推送通知iOS 8未接收
任何一個可以告訴我這可能是服務器端的問題。它顯示推送通知發送成功,但不能在設備上接收。
請參閱PHP和Xcode是這樣的嗎?
<?php
// Put your device token here (without spaces):
$deviceToken = '123213123123312321312312313131231231231232131312';
// Put your private key's passphrase here:
$passphrase = '*********';
$a = 1;
// Put your alert message here:
//$message = $_GET['msg'];
$message = $_POST['msg'];
////////////////////////////////////////////////////////////////////////////////
//$myString= $_GET['id'];
$myString= $_POST['id'];
$registrationIds =explode(',', $myString);
foreach ($registrationIds as $deviceid)
{
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'cert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.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,
'badge' => $a,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceid) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
echo $result ;
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
}
?>
在AppDelegate中的Xcode
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
}
你是否將設備令牌發送給服務器? –
是的,我正在發送 –