flutter: fcm ios push notifications doesn't work in release mode
Asked Answered
I

7

7

I have bound my flutter-iOS app to firebase and i'm also using firebase-messaging and cloud functions for sending notifications via subscribing to topics, i'm using the APNs push notifications key of apple developer account. when i use the option runner>flutter run main.dart in release mode to build my app on my phone, fcm notifications doesn't work anymore, while it works in development mode, anyone can help me fix this?

this is my index.json code:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);
 
var newData;
 
exports.messageTrigger = functions.firestore.document('notifications/{notificationsId}').onCreate(async (snapshot, context) => {
newData = snapshot.data();
const payload = {
    notification: {
        title: newData.title,
        body: newData.body,
        sound: 'default'
    },
    
        data: {
      click_action: 'FLUTTER_NOTIFICATION_CLICK',
      message: newData.title,
    }

};

if (newData.language === 'english'){
    await admin.messaging().sendToTopic('english', payload);
}
else if (newData.language === 'arabic'){
    await admin.messaging().sendToTopic('arabic', payload);
}
else if (newData.language === 'kurdish'){
    await admin.messaging().sendToTopic('kurdish', payload);
}
});

hence package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "dependencies": {
    "firebase-admin": "^8.10.0",
    "firebase-functions": "^3.6.1"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}
Inkhorn answered 7/9, 2020 at 18:9 Comment(13)
Make sure Push Notification Certification you have created supports production.Allogamy
hello, thankyou, Ihaven't distributed it in the appstore yet, just build released on my phone, does that need a certificate too?Inkhorn
im not using push notifications certificate , im using APNS keyInkhorn
please send me firebase cloud messaging settings page screenshot. where you added the apnAllogamy
how do i send it? i have uploaded the apns key correctly to firebase, it works well on android debug and release as well as ios debug, the only problem is ios release modeInkhorn
Android doesn't need APN keys. please send a link of the screenshotAllogamy
Are you using firebase functions?Allogamy
yes cloud functionsInkhorn
onedrive.live.com/…Inkhorn
show me the package.json file of the cloud functionAllogamy
i used index.json, its int the same linkInkhorn
The link is not working. Please edit the question and add the package.json code and index.json code.Allogamy
added them, thankyouInkhorn
C
9

My project got the same issue. Combined two solutions I found, it finally works. (firebase_messaging 7.0.3)

As for debug mode, you don't need these.

Step 1: Edit AppDelegate.swift

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    
    GeneratedPluginRegistrant.register(with: self)

    application.registerForRemoteNotifications()

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Step 2: Edit ios/Runner/Info.plist. Add this:

<key>FirebaseAppDelegateProxyEnabled</key>
<string>NO</string>
Craze answered 11/12, 2020 at 20:50 Comment(2)
I had similar issue and just adding this application.registerForRemoteNotifications() solved my problemJenks
Same problem application.registerForRemoteNotifications() solved my problemTranquillize
L
2

After update firebase_messaging to 7.0.0 I had the same problem. I added application.registerForRemoteNotifications() in my AppDelegate.swift and it worked!

Lauranlaurance answered 23/10, 2020 at 9:59 Comment(4)
can you edit and write the complete app delegate please?Inkhorn
it gives me an error wherever i put it in my appdelegateInkhorn
also mine is in Objective CInkhorn
@Inkhorn gist.github.com/kabazyba/cbc381aa504ab63a7de893236f77e9d2Lauranlaurance
S
1

I tried many ways. I did deep research, when i give up i checked my Xcode Settings and i saw under Signing&Capabilities -> Debug -> Notification added but Signing&Capabilities -> Release I didn't add. so i added capability and it worked look this

Subastral answered 19/3, 2022 at 12:10 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Corrales
A
0

I have the same issue. Looks like iOS release require additional notification params

To check that notification works you could try to send message directly from the firebase console.

Cloud Messaging -> Send your first message -> Enter notification title and text -> Send test message -> Enter your device token -> Test

To obtain device token you can use print(await FirebaseMessaging().getToken());

To check release logs connect the device and open Xcode -> Window -> Devices and Simulators -> Open Console

If it works you could try to add this params:

const payload = {
 notification: {
    title: newData.title,
    body: newData.body,
    sound: 'default'
 },
 data: {
    click_action: 'FLUTTER_NOTIFICATION_CLICK',
    message: newData.title,
 },
 apns: {
    headers: { "apns-priority": "5" },
    payload: {
            aps: {
                contentAvailable: true,
                category: "NEW_MESSAGE_CATEGORY"
            }
        }
    },
};

But I'm not sure which param helps: "apns-priority" or contentAvailable.

Aerophobia answered 20/10, 2020 at 20:30 Comment(0)
S
0

You have to create appropriate certificates to enable Pushnotifcation in Release mode iOS

Note : Everything will run as expected in debug mode even if you don't have Provisional Profile Certificate. But It's mandatory in release mode

  1. Apple SandBox Push service certificate
  2. Provisional Profile Certificate
  3. Apple Development, Distribution, Sigin Certificate all is mandatory

Follow the steps in the link : https://firebase.flutter.dev/docs/messaging/apple-integration/

Sankey answered 29/11, 2023 at 12:52 Comment(0)
F
0

I have same Issue, I add only one development APNs certificate to firebase and forget add product APNs certificate to firebase settings. this why ios debug work but not release

Fluster answered 17/5, 2024 at 2:47 Comment(0)
S
0

I faced same issue. I was using flutter_local_notifications: ^17.2.1+2 and firebase_messaging: ^14.6.8. I checked APNs key (.p8 file) was configured properly in firebase console and with debug mode push notification was working but for release mode it was not working through flutter run --release

What I found is I did directly drag and drop GoogleService-Info.plist file under Runner directory through Android studio and because of that, folder reference was not created. So I removed GoogleService-Info.plist and added through xCode with drag and drop file under Runner directory with selecting Create folder reference and it's worked!!!

Once we do this ios/Runner.xcodeproj/project.pbxproj will get changed.

enter image description here

This might be useful for someone who faces issue same like me.

Shellieshellproof answered 14/8, 2024 at 7:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.