我正在尝试向我在iOS 8上运行的应用发送推送通知。
我有两个设备;一个是带有iOS 8的iPad 2,另一个是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+不会。
会出现什么问题?
任何建议都将受到赞赏。
答案 0 :(得分:0)
您是否已将新iPhone6添加到开发配置文件中?然后再次下载并安装配置文件。这解决了我。
答案 1 :(得分:0)
不确定是否可以,但我收到通知时遇到了奇怪的问题,然后我从Apple文档中读到以下内容:
值为1的content-available属性允许远程通知充当静默通知。 对于静默通知,请注意确保aps词典中没有警报,声音或徽章有效负载
我注意到你的aps词典全部有3个(警报声和徽章) 文档接着说,如果是这种情况,苹果可能不会传递信息。
删除那些为我工作的人。
由于 韦恩