IPhone 6 not receiving push notification

I am trying to send a push notification to my app running on iOS 8.

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

The exact same app works on two devices and I am using the same php script to send push notification.

I am using the following c object code to enable 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)];
}

      

The following is a php script to send a push notification

function sendpush($deviceToken, $message, $test = false){
    // Put your private key 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 - App running on iPad 2 (iOS 8) gets push notification but iPhone 6+ doesn't.

What is the problem?

Any advice would be appreciated.

+3


source to share


2 answers


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



0


source


Not sure if it could be, but I had weird problems getting notifications and then I read the following from Apple's documentation:

A content availability property of 1 allows the remote notification to act as a silent notification. For silent notification, make sure there is no alert, sound or icon information in the aps dictionary

I noticed that your aps dictionary contains all 3 (beep and icon in it) The docs said that the apple cannot deliver the message if it does.



Removing the ones that worked for me.

Thanks Wayne

0


source







All Articles