fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
624 stars 990 forks source link

error InvalidApnsCredential to send ios push to Firebase #292

Open eros2187 opened 7 years ago

eros2187 commented 7 years ago

I'm experiencing this error by sending a notification ios me from InvalidApnsCredential error The certificate was generated and it has not expired and was exported and loaded into p12 in the firebase console Sending the message from the firebase console by the same error This and the script I use to send the message the same script for android works perfectly.

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'KEY SERVER ME' );
//$registrationIds = array( $_GET['id'] );
//https://developers.google.com/cloud-messaging/http-server-ref

$token = 'TOKEN ME';
$registrationIds = array($token);

// prep the bundle
/*$msg = array
(
    'body'  => $_GET['body'],
    'title'     => $_GET['title'],
    'vibrate'   => 1,
    'sound'     => 1,
);
*/
$msg = array
(
    'body'  => 'prova',
    'title'     => 'notifica',
    'vibrate'   => 1,
    'icon'  => 'myicon',/*Default Icon*/
    'sound'     => 1,
    'color'     => '#E21F1F'
);
$fields = array
(
    'registration_ids'  => $registrationIds,
    'notification'          => $msg
);

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

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
$priority="high";
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
?>

You have the same problem know how can I solve it?

djErock commented 7 years ago

Any luck here?

TCOA commented 6 years ago

Firebase spec says

To send messages to specific devices, set the to key to the registration token for the specific app instance.

So, you should check the token count when coming into your code - if it is just one, use 'to'....

ostrichegret commented 6 years ago

InvalidApnsCredential

you must add ( create ) your Apple Development Key with Push Notification Permission https://developer.apple.com/account/ios/authkey/

and app id prefix https://developer.apple.com/account/ios/identifier/bundle

to Firebase iOS app: Firebase Console -> Project -> Settings -> Cloud Messaging -> iOS app configuration

Good luck

vnavarrete17 commented 6 years ago

I've uploaded my key, but still the same issue.. (InvalidApnsCredential) If I try to sent push with juste APNS and my key file it's work perfectly. (with this script http://thrysoee.dk/apns/)

My curl request :

$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);

(No problem on android..)

vnavarrete17 commented 6 years ago

well finally it's worked after 2 days without sucess... In the firebase console use always the teamID for the App prefix ID even if you have a custom prefix for your appID ..

eros2187 commented 6 years ago

Thank you now I have abandoned this project for a moment now i try to resume everything i can send an email to cloud2187@gmail.com i wanted to ask you some things thanks

johncovele commented 6 years ago

Makaveli17, thank you, I was banging my head against the wall for 3 days and your comment fixed my problem. Use the team ID in Firebase config, NOT the app prefix as the docs explicitly tell you. I'm using the new push auth key system, not push certificates, so that may have something to do with it.

Oddly, when I created a test project from scratch and let Xcode do everything, but punched in the app prefix (not team ID) to Firebase config, pushes worked for that app. For my older legacy app, it needed the team ID. Both apps were using the same auth key.

ppetree commented 6 years ago

If, by chance, you're porting from GCM to FCM, you MUST change "registration_id" to "to" as a failure to do so will cause the invalidAPNcredential message.

phunguyenquang commented 6 years ago

Uploading APNs Authentication Key to Firebase Cloud Messaging settings works for me.

onkarvadagaonkar commented 6 years ago

@ostrichegret thank you saved my day!!!

ghost commented 5 years ago

well finally it's worked after 2 days without sucess... In the firebase console use always the teamID for the App prefix ID even if you have a custom prefix for your appID ..

Thank you so much. The ui now actually says Team ID after you save it so I had a really hard time figuring out what was going wrong here with some of my apps.

duca14036 commented 4 years ago

Solution for me in case with APNs Authentication Key : AuthKey has ID, when downloading key file it like AuthKey_XXXYYYZZZ.p8 When uploading key to firebase console you have to use XXXYYYZZZ as key id Team Id from your profile

pankaj-ag commented 4 years ago

@duca14036 Your solution worked for me. In my case, I was confused with the term key ID.

I was using the Auth key ID from apple account instead of AuthKey_XXXYYYZZZ.p8 image

iZooto-sdk commented 4 years ago

how can resolved this error ?

{
"multicast_id": 2100425764565529008, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "InvalidApnsCredential" } ]

ppetree commented 4 years ago

Go to your FCM console and check all your credential settings and make sure you have your app ID set and are using the correct code.

Sent from my iPhone, please pardon typos and autocorrect.

On Dec 5, 2019, at 5:41 AM, Amit Kumar Gupta notifications@github.com wrote:

how can resolved this error ?

{ "multicast_id": 2100425764565529008, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "InvalidApnsCredential" } ]

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

failynsedik commented 4 years ago

Solution for me in case with APNs Authentication Key : AuthKey has ID, when downloading key file it like AuthKey_XXXYYYZZZ.p8 When uploading key to firebase console you have to use XXXYYYZZZ as key id Team Id from your profile

This made me realize my mistake. Thank you!

jovanymezura commented 3 years ago

Solution for me in case with APNs Authentication Key : AuthKey has ID, when downloading key file it like AuthKey_XXXYYYZZZ.p8 When uploading key to firebase console you have to use XXXYYYZZZ as key id Team Id from your profile

this work fine for me.

lannylin commented 3 years ago

InvalidApnsCredential

you must add ( create ) your Apple Development Key with Push Notification Permission https://developer.apple.com/account/ios/authkey/

and app id prefix https://developer.apple.com/account/ios/identifier/bundle

to Firebase iOS app: Firebase Console -> Project -> Settings -> Cloud Messaging -> iOS app configuration

Good luck

Dear ostrichegret,

I have the APNS key with push notification permission. When I added it to Firebase Cloud Messaging iOS app configuration, I also correctly entered the key id and team id. But I am still getting the InvalidApnsCredential error when I use curl command to send push notifications. I can use the same curl command to send Android push notifications successfully. Just not iOS.

I have also tried removing the key and re-adding the key. That didn't make any difference. What do you suggest I try next?

Thanks a bunch!

charleston10 commented 3 years ago

InvalidApnsCredential

you must add ( create ) your Apple Development Key with Push Notification Permission https://developer.apple.com/account/ios/authkey/

and app id prefix https://developer.apple.com/account/ios/identifier/bundle

to Firebase iOS app: Firebase Console -> Project -> Settings -> Cloud Messaging -> iOS app configuration

Good luck

Solved my problem

Tks

lannylin commented 2 years ago

InvalidApnsCredential you must add ( create ) your Apple Development Key with Push Notification Permission https://developer.apple.com/account/ios/authkey/ and app id prefix https://developer.apple.com/account/ios/identifier/bundle to Firebase iOS app: Firebase Console -> Project -> Settings -> Cloud Messaging -> iOS app configuration Good luck

Solved my problem

Tks

Thanks Charlston! I don't know what happened to my cert. I had our cert guy re-create the same cert, added that to Firebase, and then everything started working again. Weird.

charleston10 commented 2 years ago

InvalidApnsCredential you must add ( create ) your Apple Development Key with Push Notification Permission https://developer.apple.com/account/ios/authkey/ and app id prefix https://developer.apple.com/account/ios/identifier/bundle to Firebase iOS app: Firebase Console -> Project -> Settings -> Cloud Messaging -> iOS app configuration Good luck

Solved my problem Tks

Thanks Charlston! I don't know what happened to my cert. I had our cert guy re-create the same cert, added that to Firebase, and then everything started working again. Weird.

I saw that my certificate had expired, so I created another one and it worked