APNS BadDeviceToken 404:Apple Ios推送开发通知

时间:2016-09-21 14:09:28

标签: ios ionic-framework apple-push-notifications apns-php

你好苹果IOS APNS伙计们, 我正面临一个特定的错误回复,状态代码:400 ad描述:错误请求

HTTP/2 400 apns-id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX {"reason":"BadDeviceToken"}400

我的应用环境: 1.ionic框架 2.离子插件:pushNotificationsV5 3.Xcode 7.1(appl编辑器)

我的PHP代码按照指示here

function sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token) {

    $milliseconds = round(microtime(true) * 1000);

    // url (endpoint)
    $url = "{$http2_server}/3/device/{$token}";

    // certificate
    $cert = realpath($apple_cert);

    // headers
    $headers = array(
        "apns-topic: {$app_bundle_id}",
        "User-Agent: My Sender"
    );

    // other curl options
    curl_setopt_array($http2ch, array(
        CURLOPT_URL => "{$url}",
        CURLOPT_PORT => 443,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_POST => TRUE,
        CURLOPT_POSTFIELDS => $message,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSLCERT => $cert,
        CURLOPT_HEADER => 1
    ));

    // go...
    $result = curl_exec($http2ch);
    if ($result === FALSE) {
        throw new Exception('Curl failed with error: ' . curl_error($http2ch));
    }

    // get respnse
    $status = curl_getinfo($http2ch, CURLINFO_HTTP_CODE);

    $duration = round(microtime(true) * 1000) - $milliseconds;

//    echo $duration;

    return $status;
}

// open connection
if (!defined('CURL_HTTP_VERSION_2_0')) {
    define('CURL_HTTP_VERSION_2_0', 3);
}
$http2ch = curl_init();
curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);

// send push
$apple_cert = '/certificates/samplepush/XXXXXX.pem';
$message = '{"aps":{"alert":"Hi!","sound":"default"}}';
$token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$http2_server = 'https://api.development.push.apple.com';   // or 'api.push.apple.com' if production
$app_bundle_id = 'com.abc.xyz';

// close connection
for ($i = 0; $i < 20; $i++) {
    $status = sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token);
    //echo "Response from apple -> {$status}\n";
    echo $status;
}

curl_close($http2ch);

注意:我更改了基于凭证的ID和令牌。

我已经逐步生成了我的.pem文件,这是正确的,设备令牌保存在我的PHP服务器中。 但是收到错误。

离子代码为 嗨@ bobby我正在使用cordova推送通知插件,我的代码是

// push notification start  
        var gcmId=0;
        var iosId=0;
          var options = {
            android: {
              senderID: "867557584587",
              icon:"alert",

            },
            ios: {
              alert: "true",
              badge: "true",
              sound: "true"
            },
            windows: {}
          };

          //localStorage.getItem('gcmRegId')
          // initialize
          $cordovaPushV5.initialize(options).then(function() {
            // start listening for new notifications
            $cordovaPushV5.onNotification();
            // start listening for errors
            $cordovaPushV5.onError();


            // register to get registrationId
            $cordovaPushV5.register().then(function(data) {
                //alert("GCM"+data);
                // if Android device.
               if(ionic.Platform.isAndroid()){
                gcmId= data;
                //alert("data"+gcmId);
                }
                // if ios device.
               if(ionic.Platform.isIOS()){
                iosId= data;
               }


            })
          });

0 个答案:

没有答案