2014-10-07 177 views
3

我试图推送通知发送到iOS上运行我的应用程序8.iPhone 6没有收到推送通知

我有两个设备;一个是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+没有。

会有什么问题?

任何意见将不胜感激。

+1

您授权您的应用程序中显示通知的方式在iOS版8.改变了我敢打赌,你的iPad已经安装了您的应用程序时,它是在iOS 7,然后你升级了iPad。通知首选项将记录在该设备上。但是,您的iPhone 6将始终拥有iOS 8,并且可能从未要求显示推送通知,因为API不同。看看https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIUserNotificationSettings_class/index.html – Asa 2014-10-08 20:42:14

+0

你有没有这方面的运气?我有一个非常类似的问题,除了在我的情况下,相同的应用程序在iPhone 5 iOS 8上收到,但不在iPad air或iPad mini上收到。所有这三个都与今晚的新应用程序一起安装,因此与以前的评论无关。所有三个使用相同的WiFi,所以它不是3G与WiFi相关。 – Nick 2014-11-29 23:59:35

+0

@adeltahir,你是如何解决这个问题的? – 2015-04-08 07:21:46

回答

0

您是否已将新的iPhone6添加到开发配置文件?然后再次下载并安装配置文件。这为我解决了它。

+0

如果设备没有添加到配置文件中,他如何安装构建但无法接收推送通知, – 2015-04-08 07:23:44

0

不知道这可能是它,但我有收到通知还,然后奇怪的问题,我读了苹果文档的以下内容:

为1的值的内容可用的属性可以让远程通知行为作为无声通知。 对于静默通知,照顾,以确保没有警报,声音或徽章在APS字典载荷

我注意到你的APS字典有所有3(在它的警报声和徽章) 的文档继续如果这种情况发生,苹果可能无法传递信息。

删除那些为我工作。

感谢 韦恩