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

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

问题描述

我尝试推送通知发送给在iOS 8上运行我的应用程序。

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

我有两个设备;一个是iPad 2的与iOS 8,另外一个是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 code允许推送通知。

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.

会是什么问题?

任何意见,将AP preciated。

Any advice will be appreciated.

推荐答案

你有没有添加新的iPhone6​​你的开发配置文件?然后下载并重新安装配置文件。这解决了我。

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

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

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