我试图向运行在iOS 8上的应用程序发送推送通知。
我有两个设备,一个是iPad 2和iOS 8,另一个是iPhone 6+。
完全相同的应用程序运行在两个设备上,我使用相同的php脚本发送推送通知。
我使用下面的目标c代码来允许推送通知。
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}下面是发送推送通知的php脚本
function sendpush($deviceToken, $message, $test = false){
// Put your private key's passphrase here:
$passphrase = '';
$pem = dirname(__FILE__) . '/ck-pushtest.pem';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $pem);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client(
$test ? 'ssl://gateway.sandbox.push.apple.com:2195' : 'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Opening SSL Connection to Push Gateway Failed." . PHP_EOL);
// Create the payload body
$data['aps'] = array(
'content-available' => 1,
'alert' => $message,
'sound' => 'default',
'badge' => 1,
);
$data['push_type'] = 'link';
$data['link'] = 'http://google.com';
$payload = json_encode($data);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if ($result) echo '******************Success********************';
else '******************Failed*****************************';
// Close the connection to the server
fclose($fp);
}
// Put your device token here (without spaces):
$deviceToken = $_REQUEST['deviceToken'];
$message = 'Hi, this is a test message!';
$test = 1;
sendPush($deviceToken, $message, $test);问题是运行在iPad 2 (iOS 8)上的应用程序接收推送通知,但iPhone 6+没有。
会有什么问题?
如有任何建议,将不胜感激。
发布于 2014-10-30 12:15:08
您是否将新的iPhone6添加到您的开发供应配置文件中?然后再下载并安装配置文件。这为我解决了问题。
发布于 2016-05-27 20:39:15
不确定是否是这样,但收到通知时我遇到了一些奇怪的问题,然后我从Apple文档中读到了以下内容:
值为1的内容可用属性允许远程通知充当无声通知。对于无声通知,请确保在aps字典中没有警报、声音或警徽有效负载。
我注意到你的aps字典中包含了所有的3(警报、声音和徽章),医生们接着说,如果是这样的话,苹果可能不会传递信息。
把那些东西移走对我有用。
谢谢韦恩
https://stackoverflow.com/questions/26243484
复制相似问题