简体   繁体   中英

Unable to get firebase messaging token. [Error: [messaging/unknown]. Too many server requests.] - React Native IOS

Im implementing Firebase Cloud Messaging notification for my React Native app. For Android, the notification works great, however, for the ios, I faced an error of unable to get the token, too many server request. Here is my snippet of code for getting FCM token + request user's notification permission

const getFcmToken = async () => {
  let fcmToken = await AsyncStorage.getItem("fcmToken");

  console.log("fcmToken", fcmToken);

  if (!fcmToken) {
    try {
      fcmToken = await messaging().getToken();
      if (fcmToken) {
        // user has a device token
        await AsyncStorage.setItem("fcmToken", fcmToken);
      }
    } catch (err) {
      console.log("Unable to get messaging token.", err);
    }
  }
};
export async function requestUserPermission() {
  const authStatus = await messaging().requestPermission();
  const enabled =
    authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
    authStatus === messaging.AuthorizationStatus.PROVISIONAL;

  if (enabled) {
    getFcmToken();
  } else {
    console.log("not enabled");
  }
}

When opening the app, the notification permission work fine, just the get FCM Token failed. Please help me with this issues.

I faced a similar issue where my app successfully retrieved FCM tokens for Android devices, whereas iOS responded with a Too many server requests error.

I solved it by re-downloading the GoogleService-Info.plist file from the Firebase Console for the iOS app.

I am not sure why, but it seemed my API key had been blocked or was invalid. After re-downloading the GoogleService-Info.plist file, the API key was updated and everything started working again.

The steps for adding the GoogleService-Info.plist to your React Native project can be found in the Getting Started part of the React Native Firebase Docs where you set up your iOS credentials.

Hope this helps.

I had this issue after I restricted the Firebase APIs to my iOS app.

To fix it I had to add the Firebase Installations API as this one uses the FID (Firebase installation ID) to target devices for message deliveries.

The Firebase installations service (FIS) provides a Firebase installation ID (FID) for each installed instance of a Firebase app.

And

Firebase Cloud Messaging uses Firebase installation IDs to target devices for message delivery.

All the APIs I had enabled were as follow:

  • FCM Registration API
  • Firebase App Distribution API
  • Firebase Cloud Messaging API
  • Firebase Installations API
  • Firebase Remote Config API
  • Mobile Crash Reporting API

Source: https://firebase.google.com/docs/projects/manage-installations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM