2

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

davdog00
  • 93
  • 2
  • 13
  • please check this, maybe it will help you. https://stackoverflow.com/a/55167613/12187270 – Nitin Gadhiya Nov 30 '22 at 09:16
  • The problem in the thread you linked was that the person uploading the build didn't actually use push notifications in their app. I am trying to receive them, but fail to do so. – davdog00 Dec 15 '22 at 14:54
  • Did you solve the issue @davdog00 ? I have a very similar issue at the moment – imtoori Jan 03 '23 at 11:15
  • @imtoori - I did not solve the issue in a standard way. What I did is I created a completely new project and configured all firebase services using flutterfire_cli, used xcodes automatic signing and not used fastlane sigh or cert this time. – davdog00 Jan 03 '23 at 13:41

4 Answers4

2

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).

mrcendre
  • 1,053
  • 2
  • 15
  • 28
  • Sorry for the late answer, I have checked my .entitlements file and it says `production`. I also checked the `Payload/AppName.app/embedded.mobileprovision` and it also says `production`. – davdog00 Dec 13 '22 at 16:32
  • Can you confirm that you downloaded the newly created provisioning profile after you enabled Push Notifications for your App ID on *developer.apple.com* ? Xcode may still use an old version of the profile. To make sure, you may delete your app's provisioning profile at `~/Library/MobileDevice/Provisioning\ Profiles`, and then disable and re-enable Xcode's automatic signing. It will download the latest version of the profile, which may fix your issue. – mrcendre Dec 14 '22 at 08:46
  • Each time I build the `.ipa` for upload, I sign the app using a profile downloaded by fastlane (generated by the command `fastlane run update_code_signing_settings use_automatic_signing:false path:ios/Runner.xcodeproj`. I have also tried to use Xcodes automatic signing (which also didn't help). Is there a way to check if the provisioning profile file has specific services enabled? Also, worth mentioning, the push notifications for my App ID on _developer.apple.com_ has been enabled a long time ago. – davdog00 Dec 14 '22 at 09:47
  • I also have tried launching my app with a console attached to my phone. When opening the app, I get this console message: [pl.my.app.bundleId] Ignore becoming foreground for application without push registration – davdog00 Dec 14 '22 at 10:35
  • Since you are using Fastlane, is the binary directly uploaded from your pipeline ? Or do you use a tool such as Transporter to upload it ? Obviously, some step in the process is altering or improperly generating the binary's signature — otherwise the App Store would not emit this warning. – mrcendre Dec 14 '22 at 11:06
  • Yes, I use transporter to upload the binary. More specificallly, fastlane does: `fastlane deliver --ipa --username --submission_information {\"export_compliance_uses_encryption\": false} --skip_metadata --skip_screenshots --team_id --api_key_path ios_upload_cert.json --precheck_include_in_app_purchases false` I need to mention, that I also tried to switch back to automatic code signing (with xcode), this is when I also didn't manage to make the push notifications to be dellivered. That time I also uploaded the binary via Xcode -> Archive – davdog00 Dec 14 '22 at 14:59
0

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 ~

Dean Villamia
  • 576
  • 11
  • 24
  • I am not able to test push notifications in debug mode, right? I haven't seen a push notification on iOS in this app for half a year now... :( – davdog00 Dec 13 '22 at 16:34
0
  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/

Quyen Anh Nguyen
  • 1,204
  • 13
  • 21
0

Delete your key in your developer account, and create another one, and upload it again on your firebase. That will solve your problem.