iPhone 6 没有收到推送通知 [英] iPhone 6 doesn't receive push notification

查看:22
本文介绍了iPhone 6 没有收到推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向在 iOS 8 上运行的应用发送推送通知.

I'm trying to send push notification to my app running on iOS 8.

我有两个设备;一个是带 iOS 8 的 iPad 2,另一个是 iPhone 6+.

I have two devices; one is iPad 2 with iOS 8 and another one is iPhone 6+.

在两台设备上运行完全相同的应用程序,我使用相同的 php 脚本发送推送通知.

Exactly the same app running on two devices and I'm using the same php script to send push notification.

我正在使用以下目标 c 代码来允许推送通知.

I'm using following objective c code to allow push notification.

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脚本

Following is the php script to send push notification

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+ 没有.


Problem is app running on iPad 2 (iOS 8) receives push notification, but iPhone 6+ doesn't.

会出现什么问题?

任何建议将不胜感激.

推荐答案

不确定是否可能是这样,但我在接收通知时也遇到了奇怪的问题,然后我从 Apple 文档中阅读了以下内容:

Not sure if this could be it but I had strange issues receiving notifications also and then I read the following from the Apple documentation:

值为 1 的 content-available 属性允许远程通知充当静默通知.对于无声通知,请注意确保 aps 字典中没有警报、声音或徽章负载

我注意到你的 aps 词典有全部 3 个(其中有提示音和徽章)文档继续说,如果是这种情况,苹果可能不会传递消息.

I noticed your aps dictionary had all 3 (alert sound and badge in it) The docs went on to say that apple may not deliver the message if this is the case.

删除那些对我有用的东西.

Removing those worked for me.

谢谢韦恩

这篇关于iPhone 6 没有收到推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆