I am developing a Flutter application and integrating Push Notifications using Firebase Cloud Messaging (FCM).
The Issue:
-
Debug Mode: Everything works perfectly. I can retrieve the APNs token and receive notifications.
-
TestFlight/Release: The app fails to retrieve the APNs token. I get the following error in the logs:
[FirebaseMessaging][I-FCM012002] Error in application:didFailToRegisterForRemoteNotificationsWithError: no valid “aps-environment” entitlement string found for application
What I have configured so far:
-
Xcode Capabilities: Enabled “Push Notifications” and “Background Modes” (Remote notifications) in the
Runnertarget. -
Apple Developer Portal: The App ID has the “Push Notifications” capability enabled.
-
Provisioning Profiles: I am using a profile that includes the “Push Notifications” capability.
-
Firebase Console: I have uploaded the
.p8APNs Authentication Key. -
Entitlements: The
Runner.entitlementsfile exists and contains theaps-environmentkey.
Despite following the official Firebase Flutter guide, the error persists specifically in the TestFlight environment. It seems like the entitlement is being stripped or not recognized during the archiving process.
My Environment:
Has anyone encountered this discrepancy between Debug and TestFlight? How can I ensure the aps-environment entitlement is correctly included in the Release build?
I have already reviewed similar questions, such as this one, but the solutions provided there (and in other older threads) have not worked for me:
I have already deleted and recreated the Provisioning Profiles multiple times.
I have ensured that the aps-environment key is set to production (or handled automatically) in the entitlements file.
I have cleaned the build folder, deleted Podfile.lock, and reinstalled pods.
It seems the older solutions might be outdated for the current Flutter/Firebase integration or the latest Xcode build system.