There’s a very specific kind of frustration every Flutter developer hits when working with iOS push notifications:
👉 Everything is set up correctly
👉 Firebase is configured
👉 Permissions are granted
but still: APNs token is null or not generating at all.
If you’ve been stuck here - you’re not alone. This is one of the most common (and confusing) issues when integrating push notifications in Flutter apps.
In this guide, We’ll walk you through why this happens and how to fix it step-by-step - based on real debugging experience.
What is APNs Token (and Why It Matters)?
Before jumping into fixes, let’s quickly understand the basics.
- APNs = Apple Push Notification service
- The APNs token is a unique device identifier required for push notifications on iOS
- Firebase Cloud Messaging (FCM) depends on it to send notifications to Apple devices
👉 No APNs token = No push notifications on iOS
Common Symptoms
If you’re facing this issue, you’ve probably seen:
- getAPNSToken() returns null.
- FirebaseMessaging.instance.getToken() works on Android but not iOS.
- Foreground/background notifications not working on iOS.
- No errors - just silent failure.
Complete Fix Guide (Step-by-Step)
Let’s fix this properly.
1️⃣ Enable Push Notifications in Xcode
This is the most commonly missed step.
Steps:
- Open your Flutter iOS project in Xcode
- Go to Runner → Signing & Capabilities
- Add: Push Notifications , Background Modes → Enable Remote notifications
👉 Without this, APNs will never generate a token
2️⃣ Upload APNs Key to Firebase
Even if your app runs, Firebase won’t deliver notifications without this.
Steps:
- Go to Firebase Console
- Project Settings → Cloud Messaging
- Upload: APNs Authentication Key (.p8) , Key ID, Team ID
👉 If this is missing → token may generate, but notifications won’t work
3️⃣ Request Notification Permission (iOS 10+)
iOS is strict. No permission = no token.
NotificationSettings settings =
await FirebaseMessaging.instance.requestPermission(
alert: true,
badge: true,
sound: true,
);
👉 Always call this before fetching token
4️⃣ Ensure You Are Testing on a Real Device
This one catches a lot of developers.
❌ APNs does NOT work on iOS Simulator
✅ Only works on real iPhone/iPad
5️⃣ Wait for APNs Token Before Fetching FCM Token
Sometimes the issue is just timing.
String? apnsToken = await FirebaseMessaging.instance.getAPNSToken();
print("APNS Token: $apnsToken");
👉 If it’s null, add a delay or retry:
Future<void> fetchAPNSToken() async {
String? token;
int retries = 0;
while (token == null && retries < 5) {
await Future.delayed(Duration(seconds: 2));
token = await FirebaseMessaging.instance.getAPNSToken();
retries++;
}
print("Final APNS Token: $token");
}
6️⃣ Check AppDelegate Configuration
Make sure your AppDelegate.swift is properly set up.
import UIKit
import Flutter
import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
7️⃣ Disable Method Swizzling (If You Know What You’re Doing)
If you’ve disabled Firebase swizzling:
FirebaseAppDelegateProxyEnabled = NO
Then you MUST manually handle APNs token:
Messaging.messaging().apnsToken = deviceToken
👉 Otherwise, token will never be registered
8️⃣ Check Bundle Identifier Matches Everywhere
Make sure this matches in:
- Apple Developer Account
- Xcode project
- Firebase project
👉 Even a small mismatch = token issues
9️⃣ Clean & Rebuild Project
Sometimes it’s just caching issues.
flutter clean
flutter pub get
cd ios
pod install
Then rebuild from Xcode.
🔍 Debug Checklist (Quick Summary)
If you’re still stuck, check this:
- Real device used
- Push Notifications enabled in Xcode
- Background modes enabled
- APNs key uploaded to Firebase
- Permissions requested
- AppDelegate configured correctly
- Bundle ID matches
- No swizzling misconfiguration
Final Thoughts
This issue feels tricky because:
- There’s no clear error
- Everything “looks” correct
- Android works fine
But once you understand the flow:
👉 iOS Permission → APNs Token → FCM Token → Notification it becomes much easier to debug.
Top comments (0)