0
votes

I try to send push notification to my Cordova Ios App.

I use the plugin cordova-plugin-fcm

For my android app it's work perfectly , the problem is for Ios , my curl request return :

InvalidApnsCredential

I have upload my Apns key on FCM and this key work because i've try to send a push notification with just Apns and it's work fine my app receive the notification.

Here the APNS script who work : http://thrysoee.dk/apns/

Here my php curl Script with FCM wich work with android but not 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"}]}

Thanks you.

1

1 Answers

0
votes

Well I finally find the problem . On firebase console use allways your apple teamID for the app prefix even if your appID have a prefixID different of your teamID