I have an issue with push notifications not being received on an iOS device in my Flutter app.
I tried to follow this guide: https://firebase.flutter.dev/docs/messaging/apple-integration/
Steps I have made to configure my push notifications:
- Register my APN from developer.apple.com on Firebase Console (Cloud Messaging -> my app)
- Used the GoogleServices-Info.plist from firebase
- Built the app and uploaded to TestFlight
- Asked the user for permission to show notifications on iOS
- Copied the fcm token from my app and pasted it into Firebase Console -> Cloud Messaging -> new campaign
- Push has not been received by my physical iPhone that has the app installed from TestFlight.
I also have made sure I have XCode configured properly and:
- I have selected Push Notifications and Background Modes (Background fetch, Remote notifications)
- I am using the proper bundle identifier (lol)
- My App ID has Push Notifications selected
- My APN key has the Push Notifications Service selected
Any idea on what I am doing wrong? Anyone experienced a similar issue?
EDIT:
This is my AppDelegate.swift
file, maybe it’s somewhat helpful in resolving my issue (worth mentioning – I didn’t touch it, it’s generated by flutter I guess):
import UIKit
import Flutter
import FirebaseMessaging
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}
Also have received such an email from Apple when submitted a build to Test Flight:
EDIT:
I have checked my .entitlements
file and it says production
. I also checked the Payload/AppName.app/embedded.mobileprovision
and it also says production
.
I also have added the APNs certificate in Firebase Messaging:
I connected my iPhone 8 to my MacBook and opened the console app for my iPhone 8. I found out, that when I launch my app, the console says:
No valid 'aps-environment' entitlement string found for application 'pl.mycompany.myproject.myapp': (null).
I suspect, it could be related to me signing, building and uploading the app using Fastlane, since I do have my aps-environment
set to development
when uploading in my myapp/ios/Runner/Runner.entitlements
I also get those prints in the console:
[pl.mycompany.myproject.myapp] Push registration with a nil environment was encountered, will not invalidate token
[pl.mycompany.myproject.myapp] Ignore becoming foreground for application without push registration
3
Answers
The ITMS-90078 issue you’re getting from the App Store indicates that the final app signature’s entitlements is missing the
aps-environment
entry. Thus, Push Notifications may not work as expected with TestFlight builds.First, make sure that all of the
.entitlements
files in your Xcode project do contain the said entry with the appropriate value (usuallydevelopment
orproduction
).Secondly, on the machine used to build the app, make sure that the local copy of the provisioning profile at
~/Library/MobileDevice/Provisioning Profiles
does contain theaps-environment
entry. If it does not, you should download the provisioning profile again and replace your local copy.Ultimately, to verify that the final provisioning profile does contain the
aps-environment
value, you could unzip the built IPA and navigate toPayload/AppName.app/embedded.mobileprovision
. You may check that the Entitlements section actually contains that key with the expected value.If not, your entitlement file(s) or provisioning profiles could be altered by one of the build phases (which is a lot less likely).
Basing from experience
I’m assuming the push notification is working when in debug mode right?
Funnily enough in my case the APNS Cert was only for development double check your apns certificate that might be the culprit!! 🙂
or might as well remake the certs ~
2. Use Flutter you don’t need to import FirebaseMessigng in AppDelegate.
– Just
import Firebase
then callFirebaseApp.configure()
inapplication
func.– If you configure firebase and newest documents use firebase cli instead of GoogleServices-Info.plist you even don’t need modify your AppDelegate
https://firebase.flutter.dev/docs/cli/
Did you call
await Firebase.initializeApp();
after callWidgetsFlutterBinding.ensureInitialized();
and before build your app?I think you should try local script to push notification to ensure
your configuration is right.
xcrun simctl push simulator-device-id app-bundle-id notification.apns
with notification.apns is file contains payload test, for example:
{ "aps": { "alert": "APNs demo", "sound": "default", "badge": 69 } }
https://sarunw.com/posts/testing-remote-push-notification-in-ios-simulator/