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];
}
答案 0 :(得分:0)
您正在使用生产APNS服务器:
ssl://gateway.push.apple.com:2195
为了让您的应用能够接收推送通知,您必须使用生产证书进行构建和签名。您可以通过生成Ad Hoc构建来实现此目的。
如果要将推送发送到在开发模式下运行应用程序的设备,则必须将通知推送到沙箱APNS服务器:
ssl://gateway.sandbox.push.apple.com:2195
Apple文档中的更多详细信息:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html