1

i am trying to send push notification to my flutter app, Android part works fine, but iOS device is not receiving push notifications (I created APN Certificate, which works fine in my another app).

Here's my configurations

main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SharedPreferences prefs = await SharedPreferences.getInstance();
  await Firebase.initializeApp();
  String? logged =
      prefs.getString('uid') == null || prefs.getString('uid') == ''
          ? null
          : prefs.getString('uid');

  initializeDateFormatting();
  Intl.defaultLocale = 'tr';
  listenChanges();
  AwesomeNotifications().initialize(
      // set the icon to null if you want to use the default app icon
      'resource://drawable/res_app_icon',
      []);

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  // Create the initialization for your desired push service here

  runApp(MyApp(
    logged: logged,
  ));
}

class MyApp extends StatefulWidget {
  MyApp({required this.logged});

  String? logged;

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Greatr',
      theme: whiteTheme,
      home: widget.logged != null ? SplashScreen() : Onboarding(),
    );
  }
}

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  AwesomeNotifications().createNotificationFromJsonData(message.data);
}

It's the same as my working example.

AppDelegate.swift

import UIKit
import Flutter
import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
     FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
   
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Also enabled Push Notifications and BackgroundModes(background fetch and remote notifications)

trying to solve this problem for 2-3 days and tried every solution, still no notification, any idea how to fix it?

Versions

awesome_notifications: ^0.0.6+10
  firebase_core: "^1.0.4"
  firebase_messaging: "^9.1.2"
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Emir Kutlugün
  • 349
  • 1
  • 6
  • 18

3 Answers3

0

from firebase documentation
Upload your APNs authentication key to Firebase. If you don't already have an APNs authentication key, make sure to create one in the Apple Developer Member Center.

Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab.

In APNs authentication key under iOS app configuration, click the Upload button.

Browse to the location where you saved your key, select it, and click Open. Add the key ID for the key (available in the Apple Developer Member Center) and click Upload.

Omar Mahmoud
  • 2,902
  • 1
  • 14
  • 22
0

I verified all the check lists twice to thrice but nothing worked. As old version,copy of code is working fine. The issue is not in the code, but in the push notification payload. You need to add notification payload, or just add it with existing data payload "notification": { "content_available":true}.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
0

If you have moved your project to a different Apple developer account like I did, don't forget to update the Team ID and APNs Authentication Key.

  1. Create new APNs key from https://developer.apple.com/account/resources/authkeys/list and download it.
  2. Go to Firebase > Project Settings > General
  3. Update Team ID after selecting your Apple app.
  4. Go to Firebase > Project Settings > Cloud Messaging
  5. Upload key from 2nd step and insert Key ID
okan
  • 790
  • 10
  • 11