推送通知无法在ios 9设备上运行

时间:2015-12-16 16:28:54

标签: ios push-notification ionic ios9 cordova-plugins

自iOS 9.0 - 9.2实施以来,我的应用程序用户正在使用它不再接收推送通知。

我的代码在发送到Android设备时工作正常,因为我将两个平台(iOS和Android)分成两个不同的阵列并相应地处理它们。

APNs服务器的结果根本不会返回错误。

是否有已知问题记录了推送通知服务器上可能发生的变化?如果是,请提供链接。

以下是我用来发送推送通知的代码(PHP):

public function send_notification($message) {

    $title = 'My App';
    $platform = '';

    $users = mysql_query("select * FROM push_devices");
    $no_of_users = mysql_num_rows($users);  

        // Initialize the array for storing the platform specific tokens
        $iOSusers = array();
        $androidUsers = array();

        if($no_of_users > 0){

            // Seperate the tokens
            while ($row = mysql_fetch_array($users)) {
                $platform = $row['platform'];
                if($platform == 'Android' || $platform == 'android'){
                    // Add to android list
                    $androidUsers[] = $row['push_id'];
                }
                if($platform == 'iOS' || $platform == 'ios'){
                    $iOSusers[] = $row['push_id'];
                }                               

            }// endwhile    
        }


        if(!empty($androidUsers)){

                $messageAndTitle = array(
                    'message' => $message,
                    'title' => $title
                );
                // Set POST variables
                $url = 'https://android.googleapis.com/gcm/send';

                $fields = array(
                    'registration_ids' => $androidUsers,
                    'data' => $messageAndTitle,
                );

                $headers = array(
                    'Authorization: key=' . ***GOOGLE_API_KEY***,
                    'Content-Type: application/json'
                );

                $ch = curl_init();

                // Set the url, number of POST vars, POST data
                curl_setopt($ch, CURLOPT_URL, $url);

                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                // Disabling SSL Certificate support temporarly
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_SSLVERSION, 3);
                curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
                // Increase the timeout
                curl_setopt($ch, CUROPT_CONNECTTIMEOUT, 1000);
                curl_setopt($ch, CURLOPT_TIMEOUT, 0);
                // Execute post
                $result = curl_exec($ch);
                if ($result === FALSE) {
                    die('Curl failed: ' . curl_error($ch));
                }
                echo $result . '<br/>';
                // close the connection
                curl_close($ch);

        } 


        // Handle iOS push
        if(!empty($iOSusers)){ 


                $ctx = stream_context_create();
                stream_context_set_option($ctx, 'ssl', 'local_cert', **PUSH_CERT_FILE**);
                stream_context_set_option($ctx, 'ssl', 'passphrase', **PUSH_PARAPHRASE**);

                // Open a connection to the APNS server
                $fp = stream_socket_client(
                    PUSH_SERVER, $err,
                    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

                if (!$fp)
                    exit("Failed to connect: $err $errstr" . PHP_EOL);

                //echo 'Connected to APNS' . PHP_EOL;
                $badgeCount = 2;
                $badge = (int)$badge;
                // Create the payload body
                $body['aps'] = array(
                    'alert' => $message,
                    'badge' => $badge,
                    'sound' => 'default'
                    );

                // Encode the payload as JSON
                $payload = json_encode($body);
                // Build the binary notification
                //Note:  $deviceToken is an array for android push
                foreach ($iOSusers as $token) {
                    $msg = chr(0) . pack('n', 32) . pack('H*', $token) . pack('n', strlen($payload)) . $payload;
                    // Send it to the server
                    $result = fwrite($fp, $msg, strlen($msg));
                    //echo 'Device token: ' .$deviceToken[0];
                    if (!$result)
                        echo 'Message not delivered' . PHP_EOL . $token . '<br/>';
                    else
                        echo 'Message successfully delivered' . PHP_EOL . $token . '<br/>';                     
                }

                fclose($fp);

        } // iOS

} 

1 个答案:

答案 0 :(得分:0)

互联网上有数百个关于不能在iOS 9上运行的通知的线程,但我认为这个问题是服务器端的。

我注意到过去几周我的iPhone 5(iOS 7.1.2)上的推送通知存在问题,我发现问题来自Apple推送通知服务器。

我现在收到大约10%的Whatsapp通知和0%的Facebook Messenger通知,但我确信其他应用也都参与其中。

使用另一个应用程序(Bspotted),最近安装,我收到100%的通知。

所以我已经下载了配置文件 PersistentConnectionLogging.mobileconfig ,以便启用推送通知的日志记录。

事实证明Apple Push Server正在使用TOKEN(null)发送通知,因此当然应用程序无法处理它们:

copyTokenForDomain push.apple.com(null)

此外,似乎我收到的令牌为null(在Whatsapp和Messenger上)的所有通知都来自Android设备。我在iPhone上收到了关于Whatsapp的消息,这是我两周内收到的第一封通知。

也许是巧合,因为现在我设法从Android设备上接收了Whatsapp上10%的通知(两周时它是0%)。

我尝试了所有这些:

  • 重置应用内通知
  • 重置iOS应用通知
  • 重新安装应用
  • 重置iOS网络配置
  • 强制iPhone重启
  • 卸载应用程序,将日期设置为提前2天,重新安装应用程序(以强制应用程序询问通知权限)

我希望这会有所帮助。

最好的问候