15

Everything was working fine before but now firebase can't seem to create a new token. I'm trying to call await FirebaseMessaging.instance.getToken(); but getting this error


FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
    NSLocalizedFailureReason = "Too many server requests.";
}
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: [firebase_messaging/unknown] An unknown error has occurred.
#0      MethodChannelFirebaseMessaging.getToken (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:226:7)
<asynchronous suspension>
#1      _SignUpState._sendVerificationCode (package:shuri_parent/src/pages/sign_up.dart:343:25)
<asynchronous suspension>
#2      _SignUpState.build.<anonymous closure> (package:shuri_parent/src/pages/sign_up.dart:252:43)
<asynchronous suspension>

I'm using firebase_messaging: : ^10.0.9

My application is broken in production, I really need your help guys.

This is my flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 2.3.0-17.0.pre.121, on Mac OS X 10.15.7 19H1419
    darwin-x64, locale en-RW)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.61.0)
[✓] Connected device (2 available)

• No issues found!

Also my app is just recently deployed and doesn't have more than 10 users, other can't seem to use the app due to this blocker. Your help will be much appreciated.

0

15 Answers 15

9

This issue is caused by limited permission to your api key from Google cloud console, here are steps that fixed my issue,

  1. Login to Google cloud console and select your current project

  2. Select **API Credentials - APIs & Services ** or IAM Permissions on left sidebar.

  3. Select iOS key(auto created by firebase)'s menu on right if you have selected **API Credentials - APIs & Services **

  4. Select Edit API key

  5. Under the Selected APIs: dropdown menu select these options: Firebase Installations API, Firebase Cloud Messaging API & FCM Registration API

Google Cloud - iOS key restriction

Sign up to request clarification or add additional context in comments.

1 Comment

It did not work for me. I tried only to do the solution, but it did not work. I tried to clean the project and reinstall the firebase files and it worked after several tries.
7

Oh! my bad, I found the issue. My issue was a wrong api key of firebase in the GoogleServices-info.plist file

Thanks for all the support you gave me.

Comments

7

I resolved this issue by redownloading the GoogleService-Info.plist from the firebase & replace the current file.

1 Comment

In Firebase, go to Project (iOS) -> click gear icon -> Apple apps -> click download of GoogleService-Info.plist
4

in my case I have different bundle identifier on Xcode and in Firebase Console.

I have this issue after implementing Flavor on Flutter app. the Bundle Identifier is created dynamically based on the scheme on my Xcode

Comments

4

make sure you add push notification config in xcodeenter image description here

Comments

4

I have already faced this problem and searched a lot but did not find a solution.. But when I changed the emulator the problem was solved

Change the emulator

1 Comment

Thanks man this worked! it seems the prev Simulator has cached some data
2

I was having the same issue on all of my IOS simulators, tried multiple things:

  1. flutter clean
  2. flutter pub get

but it didn't work.

The issue was with the FCM token for firebase push notifications. You wouldn't face this issue on any physical device , but if you have to work on the simulator than the solution that i figured was i commented out:

final fCMToken = await FirebaseMessaging.instance.getToken();

After this i stopped having the issue so i did all the work on the simulator and when i had to push out the build i enabled it again and it was working fine on the physical device.

2 Comments

This is not ideal but sadly the only workaround that works in my case
Yes its not a good practice but hope this issue is solved so wouldn't have to do this step to make it work on simulator.
1

In my case, i was using a different bundle id in debug and profile, and the key under APIs & Services => Credentials => iOS key (could be 2 keys, auto created by Firebase and auto created by Google Service) was set to iOS app restriction using the release bundle id, so, you need to add your debug bundle id here in the restrictions.

enter image description here

enter image description here enter image description here enter image description here

Comments

1

Emulators often encounter issues with receiving notifications, especially on iOS, as many emulators don't fully support this functionality.

Testing on a real device should resolve the problem.

Comments

1

I found a solution for the simulators in iOS:

https://github.com/firebase/flutterfire/issues/13575

"in iOS , use getAPNSToken instead of getToken and it will be work"

1 Comment

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
0

Make sure that your Flutter app targets iOS 8 or later. Please check this link below

https://firebase.google.com/docs/flutter/setup?platform=ios

in some android and ios devices not receiving firbase base responce because of its versions and api level

1 Comment

Yes it has target IOS 10.0, Befor It was working fine in production until it started showing that error only on getToken() on users mobile phones.
0

APns Was Null valeu And Problem with get Token When itry it in ios >12 It Work

  firebase_core: ^2.11.0 firebase_messaging: ^14.2.5 it support for me only the ios 13 and higher     <key>FirebaseAppDelegateProxyEnabled</key>
<true/> 
import UIKit
import Flutter
import Firebase
@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    //FirebaseApp.configure()
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
# Uncomment this line to define a global platform for your project
platform :ios, '13.0'
swift_version = '5.0' 
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'NO'
    end
  end
end

end
# target 'ImageNotification' do
#   use_frameworks!
#   pod 'Firebase/Messaging' , '~>10.7.0'
# end

Comments

0

The problem was not enabled the Push Notifications capability through XCode.

Comments

0

I had the same Problem

  1. Upgrade your all firebase flutter packages in pubspec.yaml
  • firebase_core
  • firebase_crashlytics
  • firebase_analytics
  • firebase_messaging
  1. flutter clean
  • Remove pubspec.lock
  • flutter pub get
  • go to /iOS Directory
  • remove /Pods Directory in your project
  • remove Podfile.lock
  • flutter run
  • if that didn't work try 2 step again except flutter run and follow below steps
    • cd /ios
    • pod install or pod install --repo-update
    • flutter run

Comments

-2

Turn out the error throw because I'm using a vpn app. Try to change your network to a different network then try again

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.