【问题标题】:push notification not working on ios 9 devices推送通知在 ios 9 设备上不起作用
【发布时间】:2016-03-22 21:29:24
【问题描述】:

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

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

来自 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

} 

【问题讨论】:

  • 您找到解决方案了吗?我也有同样的问题。
  • 我不知道,但我大约一周前在 12 台设备上测试了远程推送通知(所有这些设备都在 iOS 9.2 或 9.2.1 上)并且效果很好。服务器端虽然是红宝石。

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


【解决方案1】:

互联网上有数百条关于通知在 iOS 9 上不起作用的帖子,但我认为问题出在服务器端。

在过去的几周里,我注意到我的 iPhone 5 (iOS 7.1.2) 上的推送通知存在问题,我发现该问题源自 Apple Push Notification Server。

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

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

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

原来 Apple Push Server 正在发送带有 TOKEN (null) 的通知,所以应用程序当然无法处理它们:

copyTokenForDomain push.apple.com (null)

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

也许是巧合,因为现在我设法在 Whatsapp 上收到了 10% 的通知,也来自 Android 设备(两周内为 0%)。

我尝试了所有这些:

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

我希望这会有所帮助。

最好的问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2015-11-16
    相关资源
    最近更新 更多