在IOS上使用FCM发送推送通知

时间:2017-08-01 13:34:05

标签: php ios apple-push-notifications firebase-cloud-messaging cordova-plugin-fcm

我尝试向我的Cordova Ios App发送推送通知。

我使用插件cordova-plugin-fcm

对于我的Android应用程序,它的工作完美,问题是Ios,我的卷曲请求返回:

  

InvalidApnsCredential

我已经在FCM上传了我的Apns密钥并且这个关键工作因为我尝试发送只有Apns的推送通知,并且它的工作正常我的应用程序收到通知。

这里是工作的APNS脚本:http://thrysoee.dk/apns/

这里我的php curl脚本与FCM一起使用android而不是Ios:

    $pushUrl    = "FCM_PUSH_URL"; //https://fcm.googleapis.com/fcm/send
    $key        = "SERVER_KEY";//Server key get in FCM console
    $ch         = curl_init($pushUrl);
    $headers    = [];

    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization:key=' . $key;
    $data  = array(
        "notification" => array(
            "title"         => "Bonjour le monde !",
            "body"          => "Notif de test",
            //"click_action"  =>"FCM_PLUGIN_ACTIVITY",
            "icon"          => "fcm_push_icon",
        ),
        "data" => array(
          'msg'     => 'hello',
          'msg2'    => 'world'
        ),
        "to"        => "MY_IOS_REGISTER_TOKEN"//token get on my ipad with the getToken method of cordova plugin,
        "priority" => "high",
    );

    $json_data = json_encode($data);

    curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $res = curl_exec($ch);
    curl_close($ch);

    echo "<pre>" . print_r($res,true) . "</pre>"; exit;//{"multicast_id":xxxx,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidApnsCredential"}]}

谢谢你。

1 个答案:

答案 0 :(得分:0)

好吧,我终于找到了问题。在firebase控制台上,使用 allways 您的apple teamID作为应用前缀,即使您的appID的前缀ID与您的teamID不同