skip to Main Content

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:

  1. Register my APN from developer.apple.com on Firebase Console (Cloud Messaging -> my app)
  2. Used the GoogleServices-Info.plist from firebase
  3. Built the app and uploaded to TestFlight
  4. Asked the user for permission to show notifications on iOS
  5. Copied the fcm token from my app and pasted it into Firebase Console -> Cloud Messaging -> new campaign
  6. 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:

  1. I have selected Push Notifications and Background Modes (Background fetch, Remote notifications)
    enter image description here
  2. I am using the proper bundle identifier (lol)
  3. My App ID has Push Notifications selected
    enter image description here
  4. My APN key has the Push Notifications Service selected
    enter image description here

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:
enter image description here

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:
enter image description here

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


  1. 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 (usually development or production).

    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 the aps-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 to Payload/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).

    Login or Signup to reply.
  2. 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 ~

    Login or Signup to reply.
    1. Did you add certificate in firebase project? List item

    2. Use Flutter you don’t need to import FirebaseMessigng in AppDelegate.
    – Just import Firebase then call FirebaseApp.configure() in application 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/

    1. Did you call await Firebase.initializeApp(); after call WidgetsFlutterBinding.ensureInitialized(); and before build your app?

    2. 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/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search