iPhone 6 doesn't receive push notification

拥有回忆 提交于 2019-12-22 10:03:15

问题


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

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

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

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)];
}

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);

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

What would be the issue?

Any advice will be appreciated.


回答1:


Have you added the new iPhone6 to your Development Provisioning Profile? Then download and install the profile again. This solved it for me.




回答2:


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:

The content-available property with a value of 1 lets the remote notification act as a silent notification. For a silent notification, take care to ensure there is no alert, sound, or badge payload in the aps dictionary

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.

Thanks Wayne



来源:https://stackoverflow.com/questions/26243484/iphone-6-doesnt-receive-push-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!