Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

FirebaseMessaging.getAPNSToken() returns null on iOS

ErrorFirebaseMessaging.instance.getAPNSToken() returns null

Short answer

getAPNSToken() gives null when iOS has not handed the app an APNs token yet or never will. The usual reasons: no APNs key in Firebase, push and remote-notification capabilities missing in Xcode, method swizzling off, or the call made too early. Check each, and ask for the token again after permission is granted.

  • Applies to Flutter 3.x stable, firebase_messaging, Xcode 26, iOS 18 or newer
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask for notification permission first, then request the token, and print both. If permission is denied, none of the causes below matter.

    final settings = await FirebaseMessaging.instance.requestPermission();
    debugPrint('permission: ${settings.authorizationStatus}');
    final apns = await FirebaseMessaging.instance.getAPNSToken();
    debugPrint('apns: $apns');
  2. 2Match what you see, then jump to its fix

    1. 1null on the first call, but a later call returns a valueThe token is requested before iOS has delivered itFix
    2. 2Permission is granted but the token stays null on every launchPush Notifications and background modes are not enabled in XcodeFix
    3. 3The APNs token exists on the device, but pushes sent from Firebase never arriveNo APNs authentication key has been uploaded to FirebaseFix
    4. 4FirebaseAppDelegateProxyEnabled is NO in Info.plistMethod swizzling is switched offFix

What does the error look like?

  • FirebaseMessaging.instance.getAPNSToken() returns null

Cause 1 of 4

The token is requested before iOS has delivered it

1Check

Firebase documents that the APNs token is not guaranteed to exist when the FCM plugin is called, and that from iOS SDK 10.4.0 it must exist before any FCM API request. Log the value a few seconds after launch to see if it appears.

await Future.delayed(const Duration(seconds: 3));
debugPrint('apns: ${await FirebaseMessaging.instance.getAPNSToken()}');

2Fix

Request permission, then read the APNs token, and call other FCM methods (such as getToken) only when it is not null. If it is null, retry after a short delay.

await FirebaseMessaging.instance.requestPermission();
String? apns;
for (var i = 0; i < 5 && apns == null; i++) {
  apns = await FirebaseMessaging.instance.getAPNSToken();
  if (apns == null) await Future.delayed(const Duration(seconds: 1));
}
if (apns != null) {
  final fcm = await FirebaseMessaging.instance.getToken();
}

3Verify

The log prints a long hex string for apns, and getToken returns an FCM token.

flutter run --release

Confirmed by firebase.google.com

Did this fix it?

Cause 2 of 4

Push Notifications and background modes are not enabled in Xcode

1Check

Open ios/Runner.xcworkspace, select the Runner target, Signing and Capabilities. Firebase says push notifications and the Background fetch and Remote notifications background modes must be enabled.

open ios/Runner.xcworkspace

2Fix

Add the Push Notifications capability, and under Background Modes tick Background fetch and Remote notifications.

# Xcode: Runner target > Signing & Capabilities
# + Capability > Push Notifications
# + Capability > Background Modes > Background fetch, Remote notifications

3Verify

Rebuild and run on a device. The token is no longer null.

flutter clean && flutter run

Confirmed by firebase.google.com

Did this fix it?

Cause 3 of 4

No APNs authentication key has been uploaded to Firebase

1Check

In the Firebase console open Project settings, Cloud Messaging tab, and look under APNs authentication key. Firebase requires at least one key, development or production.

# Firebase console > Project settings > Cloud Messaging > Apple app configuration

2Fix

Create a key in the Apple Developer account and upload the .p8 file with its key ID and your team ID.

# Upload: the .p8 file, the Key ID, and the Apple Team ID

3Verify

Send a test message from the Firebase console to the device token.

# Firebase console > Messaging > New campaign > Send test message

Confirmed by firebase.google.com

Did this fix it?

Cause 4 of 4

Method swizzling is switched off

1Check

The FCM Flutter plugin needs method swizzling on Apple platforms. If the flag is NO, the plugin never sees the APNs token iOS hands to the app delegate.

grep -A1 FirebaseAppDelegateProxyEnabled ios/Runner/Info.plist

2Fix

Remove the key (the default is enabled) or set it to true.

<key>FirebaseAppDelegateProxyEnabled</key>
<true/>

3Verify

Rebuild the app; getAPNSToken returns a value on a device.

flutter run

Confirmed by firebase.google.com

Did this fix it?

How do I stop it coming back?

  • Wrap token logic in one function that requests permission first, then waits for the APNs token.
  • Keep the push and background-mode capabilities in the committed Xcode project.
  • Upload both a development and a production APNs key.
  • Leave method swizzling on unless you map the APNs token by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Xcode cannot find GoogleService-Info.plist for the Runner target

error: Build input file cannot be found: '/Users/GoogleService-Info.plist' (in target 'Runner' from project 'Runner')

Xcode's project file lists GoogleService-Info.plist as an input, but nothing exists at the path it records.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.