arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1k stars 1.55k forks source link

iOS Failed to fetch default token #74

Closed imbrendino closed 7 years ago

imbrendino commented 7 years ago

Hi, I have this error:

<FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"

But when I do window.FirebasePlugin.getInstanceId at the beginning, it gives me the token...

Could you help me?

Thanks

arivanbastos commented 7 years ago

Same issue here. My device runs ios 10 and I'm using version 0.1.14.

robertarnesson commented 7 years ago

not really a problem with the plugin but rather with firebase itself. can you recieve notifications?

arivanbastos commented 7 years ago

I can't. Android works fine. I'm checking the configuration process to see if I miss something;

c4software commented 7 years ago

If its like me, its a problem on Google side. I got this error until I sign my app in production...

It's strange because everything seems correctly set but it's fail ... In dev

arivanbastos commented 7 years ago

Cant receive notifications on iOS. What I done: 1) Created the DEV/PROD provisioning profiles on developer.apple.com. Checked my developer/team certificates when creating the provisioning profiles. 2) Created the DEV/PROD APS certificates on developer.apple.com. 3) Installed developer/team certificates on dev machine. 4) Installed DEV/PROD APS certificates on dev machine. 5) Installed provisionig profiles on dev machine. 6) Installed plugin with "cordova plugin add cordova-plugin-firebase@0.1.14". 7) Added code to my app:

window.FirebasePlugin.grantPermission();
window.FirebasePlugin.getInstanceId(
  function(token) {
      thiss.saveToken(token);
  },
  function(error) {
      console.log(error);
  }
);

window.FirebasePlugin.onNotificationOpen(
  function(notification) {                  
    //alert("Yeahh!");
  }, 
  function(error) {
    //alert("Error");
  }
);

8) Created Google GCM/Google Firebase Account. 9) Added my app to Firebease with iOS/Android platforms. 10) Added APS certificates to "Cloud Messaging" section on firebase project settings. 11) Downloaded GoogleService-Info.plist e google-service.json and placed them in my app root folder. 12) Builded the app. 13) In XCode enabled "Push Notifications" and "Background Modes: Remove notifications".

I already: 1) Checked the app bundle. 2) Updated cordova. 2) Removed and reinstall iOS platform.

What I didn't: 1) Deploy the app to apple store. I'm running the app in DEBUG mode.

robertarnesson commented 7 years ago

running in debug is the problem I believe. see https://github.com/arnesson/cordova-plugin-firebase/issues/45

c4software commented 7 years ago

Definitely looks like the same « problem ».. try to upload a test version on Apple store.

imbrendino commented 7 years ago

Maybe I found the problem but I haven't tried yet. I did all the certificate for the push notifications. Now the console doesn't show the error.

imbrendino commented 7 years ago

I've tried. the problem is the same

juliocbcotta commented 7 years ago

If your app was working before you updated your XCode to Xcode 8.0, try to downgrade to XCode 7.3. This is a workaround, since XCode 8.0 the way it signs the app changed. Link do download XCode 7.3 : http://stackoverflow.com/questions/10335747/how-to-download-xcode-4-5-6-7-8-and-get-the-dmg-or-xip-file

rklus16 commented 7 years ago

I'm only able to get the token right when the app initializes. otherwise the the getToken method returns null on both iOS and Android.

arivanbastos commented 7 years ago

Ok, after publish to Apple Store I can receive push notifications sended trough Firebase console but I can't receive push notifications sended by API. I'm using PHP to send notifications:

$data = Array
(
    [to] => <token>
    [notification] => Array
        (
            [title] => My Title
            [text] => Notification test
            [sound] => default
            [vibrate] => 1
            [badge] => 0
        )

)

$jsonData = json_encode($data);
$ch     = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array(
  'Content-Type: application/json',
  "Authorization: key=".$gcmApiKey
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

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

echo $result;

Firebase API returns {"multicast_id":904572753471539870406,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1477063422322568734%3d5c78243d5c7824"}]}

Push notifications sended through API to Android devices are arriving. This problem has something to do with this plugin?

robertarnesson commented 7 years ago

you are not setting a priority. firebase console sends with high priority as default

arivanbastos commented 7 years ago

According docs (https://firebase.google.com/docs/cloud-messaging/http-server-ref) priority is optional and the default value is normal. Even after setting this value on my data the notification dont arrives on iOS.

robertarnesson commented 7 years ago

¨well you are doing something wrong on the server side, since its working through firebase. is your server whitelisted and allowed to send notifications to your app?

arivanbastos commented 7 years ago

I'm sorry, but I cant find how to do this. I thought that when using the gcm key my server would already authorized. Also, docs (https://developers.google.com/cloud-messaging/http) dont talk about whitelisting. Also, I forgot to mention but push notifications sended through API to android devices are arriving.

arivanbastos commented 7 years ago

Adding priority="high" solves the problem! Thank you all!

pavloPyrig0 commented 7 years ago

I also have the same issue, doesnt work on ios.

chanphillip commented 7 years ago

I'm getting the same problems.

Failed to fetch APSN token Error Domain=com.firebase.iid Code=1001 "(null)"

And also this

Unable to connect to FCM. Error Domain=com.google.fcm Code=501 "(null)"

Edited: Although there are those error messages, it still works at the end. It got the token and could receive push messages successfully.

Shakti-Sharma commented 6 years ago

The Same issue is resolved on the following link.

https://github.com/firebase/quickstart-ios/issues/111

Regards Shakti