Why the FCM not working on ios in flutter
1,285
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
}
add this to your appDelegate.... here is example of appDelegate
import UIKit
import Flutter
import Firebase
import FirebaseAuth
import UserNotifications
import FirebaseMessaging
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
application.registerForRemoteNotifications()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
}
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let firebaseAuth = Auth.auth()
if (firebaseAuth.canHandleNotification(userInfo)){
print(userInfo)
return
}
}
}
Author by
Mariam Younes
Updated on December 31, 2022Comments
-
Mariam Younes over 1 year
I'm Following this steps to add push notification to my app using firebase messaging but after all of this steps it doesn't work
<key>FirebaseAppDelegateProxyEnabled</key> <false/> final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); void firebaseTrigger(BuildContext ctx) async { _firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { print("onLaunch: $message"); Fluttertoast.showToast( msg: message['notification']['title'], toastLength: Toast.LENGTH_LONG, gravity: ToastGravity.TOP, timeInSecForIosWeb: 6, ); }, onLaunch: (Map<String, dynamic> message) async { Navigator.push( context, MaterialPageRoute( builder: (context) => NotificationScreen(), ), ); }, onResume: (Map<String, dynamic> message) async { Navigator.push( context, MaterialPageRoute( builder: (context) => NotificationScreen(), ), ); }, ); } @override void initState() { super.initState(); firebaseTrigger(context); _firebaseMessaging.requestNotificationPermissions( const IosNotificationSettings( sound: true, badge: true, alert: true, provisional: true)); _firebaseMessaging.onIosSettingsRegistered .listen((IosNotificationSettings settings) { print("Settings registered: $settings"); }); }
But the push notification doesn't work for ios only but it works on android so kindlly can anyone help me in my problem
Edit: my appDelegate
-
Gbenga B Ayannuga over 2 yearsare u runing on simulator?
-
Abhijith over 2 yearscheck the documentation i am not familiar with ios, but go through this also firebase.flutter.dev/docs/messaging/apple-integration
-
Mariam Younes over 2 years@GbengaBAyannuga no in real device
-
Mariam Younes over 2 years@Assassin I'm following this document but same problem
-
Gbenga B Ayannuga over 2 yearslet me see your payload
-
Mariam Younes over 2 years@GbengaBAyannuga I'm send the notification from firebase console
-
-
Mariam Younes over 2 yearsshould i remove this if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate } from my appDelegate and put yours ?
-
Gbenga B Ayannuga over 2 yearsremove it... after adding it.... update let me see where u paste it
-
Mariam Younes over 2 yearsis this answer will make the ios notification permission appear ??