firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.71k stars 3.97k forks source link

[firebase_messaging]: onBackgroundMessage wont call on iOS, works on Android #11785

Closed hajajmaor closed 1 year ago

hajajmaor commented 1 year ago

Is there an existing issue for this?

Are you aware of the differences between iOS and Android background message handling?

Do you have an active Apple Developer account?

Are you using a physical iOS device to test background messages?

Have you enabled "Remote Notifications" & "Background Mode" (Checking options for "Background Processing" & "Remote Notifications") in your app's Xcode project?

Scree

Have you created an APNs key in your Apple Developer account & uploaded this APNs key to your Firebase console?

2

Have you disabled method swizzling for Firebase in your app?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>AppGroupId</key>
    <string>$(CUSTOM_GROUP_ID)</string>
    <key>BGTaskSchedulerPermittedIdentifiers</key>
    <array>
        <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    </array>
    <key>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>$(APP_DISPLAY_NAME)</string>
    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>ShareHandler</string>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.file-url</string>
                <string>public.image</string>
                <string>public.text</string>
                <string>public.movie</string>
                <string>public.url</string>
                <string>public.data</string>
            </array>
        </dict>
    </array>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>------</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>-----j</string>
                <string>ShareMedia-$(PRODUCT_BUNDLE_IDENTIFIER)</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>LSSupportsOpeningDocumentsInPlace</key>
    <string>No</string>
    <key>NSCameraUsageDescription</key>
    <string>Requesting access to the camera</string>
    <key>NSContactsUsageDescription</key>
    <string>Requesting access to the contact list</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>We need your location even when the app is in the background.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to location when in the background.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to location when open.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>We need to access to the microphone to record audio file</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Photos can be shared to and used in this app</string>
    <key>NSUserActivityTypes</key>
    <array>
        <string>INSendMessageIntent</string>
    </array>
    <key>UIApplicationSupportsIndirectInputEvents</key>
    <true/>
    <key>UIBackgroundModes</key>
    <array>
        <string>audio</string>
        <string>fetch</string>
        <string>location</string>
        <string>processing</string>
        <string>remote-notification</string>
        <string>voip</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen.storyboard</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiresFullScreen</key>
    <true/>
    <key>UIStatusBarHidden</key>
    <false/>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>FirebaseScreenReportingEnabled</key>
    <true/>
    <key>FirebaseAppDelegateProxyEnabled</key>
    <true/>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>io.flutter.embedded_views_preview</key>
    <true/>
</dict>
</plist>

Are you sending messages to your app from the Firebase Admin SDK?

Worked with the example project with the same Firebase project.

Have you requested permission from the user to receive notifications?

Have you used the 'Console' application on your macOS device to check if the iOS device's system is throttling your background messages?

20:11:38.044985+0300 wifid -[WiFiUsagePoorLinkSession linkQualityDidChange:]: rssi:-78dBm recomm:N/A 20:11:38.045203+0300 wifid -[WiFiUsagePoorLinkSession linkQualityDidChange:] BadLink session (active:YES start:2023-10-26 14:47:50 +0000 end:(null) network:DontTry) - rssi:-78, core0:0, core1:0, sum_of_rssi:-686900, count_of_lqm:8508, sumof_core0Diff:-468021, sumof_core1Diff:-469474 20:11:38.045612+0300 wifid +[WiFiUsageLQMTransformations ratePercentagesWithTxRate:rxRate:txFallbackRate:txFrames:rxFrames:nss:bw:phyMode:band:deviceMaxRate:]: linkMaxRate for nSS:2 bw:80 phy:11ac : 866700 20:11:38.234951+0300 kernel AppleCS42L77Audio::micBiasFastRampDown BiasCtrl:0 20:11:38.330823+0300 kernel AppleCS42L77Audio::micBiasFastRampDown BiasCtrl:0 20:11:38.763974+0300 kernel wlan0:com.apple.p2p: isInfraRealtimePacketThresholdAllowed allowed:0 option:0 threshold:50 noRegistrations:1 cachedPeerCount:0 fastDiscoveryInactive:1 fastDiscoveryOnSince:123820680 20:11:38.798665+0300 apsd Setting gAssertionsOffloader timeout to 1 20:11:38.798877+0300 apsd Created power assertion {identifier: APSCourier(tcpStream:dataReceived:)-NonCellular} 20:11:38.800465+0300 apsd : Outstanding data received: (length 1088) onInterface: NonCellular. Connected on 1 interfaces. 20:11:38.800668+0300 apsd : Stream processing: complete yes, invalid no, length parsed 1084, parameters 20:11:38.801152+0300 apsd Created power assertion {identifier: com.apple.apsd-delayed-keepalive-sandbox.push.apple.com-NonCellular} 20:11:38.802788+0300 apsd incoming message is for proxy client that is not connected. baseToken destToken publicTokens 20:11:38.803150+0300 apsd timestampForTopic? token 20:11:38.803386+0300 apsd isAppSpecificTokenValid sandbox.push.apple.com ,PerAppToken.v0 20:11:38.811060+0300 apsd isAppSpecificTokenValid? found cached token YES 20:11:38.811161+0300 apsd isAppSpecificTokenValid sandbox.push.apple.com ,ExtendedAppToken.v1 20:11:38.812258+0300 apsd SecItemCopyMatching() returned no items found. 20:11:38.812335+0300 apsd isAppSpecificTokenValid? found cached token NO 20:11:38.812393+0300 apsd hasPayload? forTopic tokens 20:11:38.812453+0300 apsd copyAppSpecificTokensWithDomain sandbox.push.apple.com ,PerAppToken.v0 20:11:38.814625+0300 apsd copyAppSpecificTokensWithDomain - sandbox.push.apple.com for topic account 20:11:38.816478+0300 apsd copyAppSpecificTokensWithDomain sandbox.push.apple.com ,ExtendedAppToken.v1 20:11:38.817481+0300 apsd SecItemCopyMatching() returned no items found. 20:11:38.817604+0300 apsd receivedPushWithTopic token payload timestamp 1698340298759050659 20:11:38.817925+0300 apsd : Received message for enabled topic '' onInterface: NonCellular with payload '' with priority 10 for device token: NO isProxyMessage: NO 20:11:38.818012+0300 apsd : Push has been read from stream and parsed. UUID: (null) 20:11:38.818176+0300 apsd APSPowerLog: {event: , dict: } 20:11:38.818449+0300 apsd asked to store incoming message with guid environment 20:11:38.819288+0300 apsd APSMessageStore - New message record [] has ID [344]. 20:11:38.819386+0300 apsd : Sending acknowledgement message with response 0 and messageId (2938010112) 20:11:38.819535+0300 apsd : Sending Push ACK. UUID: (null) 20:11:38.819832+0300 apsd _notifyForIncomingMessage with guid 20:11:38.819988+0300 apsd : Sending push to client. UUID: (null) 20:11:38.821083+0300 apsd : Stream processing: complete yes, invalid no, length parsed 4, parameters 20:11:38.821270+0300 apsd : Received keep-alive response 1 on interface NonCellular:

Additional context and comments

pubspec.yaml ```yaml name: intune_app description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # In Android, build-name is used as versionName while build-number used as versionCode. # Read more about Android versioning at https://developer.android.com/studio/publish/versioning # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. version: 0.2.7+4 environment: sdk: ">=3.0.5 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions # consider running `flutter pub upgrade --major-versions`. Alternatively, # dependencies can be manually updated by changing the version numbers below to # the latest version available on pub.dev. To see which dependencies have newer # versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter desktop_window: ^0.4.0 ### State management provider: ^6.0.5 flutter_riverpod: ^2.3.6 ### Firebase firebase_app_check: ^0.2.1+1 firebase_auth: ^4.7.2 firebase_core: ^2.19.0 firebase_crashlytics: ^3.3.4 firebase_messaging: ^14.7.1 firebase_performance: ^0.9.2+4 firebase_storage: ^11.2.5 cloud_functions: ^4.3.4 cloud_firestore: ^4.8.5 ### Getstream.io chat stream_chat_flutter_core: ^6.8.0 stream_chat_persistence: ^6.8.0 ### Phone services flutter_contacts: ^1.1.7+1 # Web & Mac & Linux not included share_plus: ^7.0.2 camera_macos: ^0.0.6+5 share_handler: ^0.0.17 ### utils dio: ^5.2.1+1 async: ^2.11.0 equatable: ^2.0.5 lottie: ^2.3.2 libphonenumber: ^2.0.2 # Missing: web & mac & windows & linux flutter_launcher_icons: ^0.13.1 fc_native_video_thumbnail: ^0.5.2 connectivity_plus: ^4.0.1 table_calendar: ^3.0.9 # TODO: Change to release version when this branch is merged timezone: ^0.9.2 sentry_flutter: ^7.9.0 shared_preferences: ### Calls agora_rtc_engine: ^6.2.3 # Missing: web & linux replay_kit_launcher: ^1.0.0 # Screen Capture for ios ### google apis google_speech: ^2.2.0 # Missing: web flutter_google_places_sdk: ^0.3.2+9 flutter_google_places_sdk_platform_interface: 0.2.4+3 google_maps_flutter: ^2.3.1 # Missing: web & mac & windows & linux # agora_rtc_engine: ^6.1.0 # Missing: web & linux # audio_waveforms: ^1.0.4 # Missing: web & mac & windows & linux badges: ^3.1.2 cached_network_image: ^3.2.3 # Missing: web & windows & linux carousel_indicator: ^1.0.6 carousel_slider: ^4.2.1 chip_list: ^2.4.3+8 collection: ^1.17.1 crop_your_image: ^0.7.5 device_info_plus: ^9.0.3 # ffmpeg_kit_flutter: ^5.1.0 # Missing: web & windows & linux file_picker: ^5.0.2 fimber: ^0.7.0 flutter_callkit_incoming: ^2.0.0+1 # Missing: web & mac & windows & linux # flutter_contacts: ^1.1.6 # Missing: web & mac & windows & linux flutter_easyloading: ^3.0.5 flutter_flavor: ^3.1.1 flutter_image_compress: ^2.0.3 # Missing: mac && windows & linux flutter_keyboard_visibility: ^5.4.1 flutter_local_notifications: ^15.1.0+1 # Missing: web && windows flutter_native_splash: ^2.3.1 # Missing: mac & windows & linux flutter_secure_storage: ^8.0.0 flutter_svg: ^2.0.7 geocoding: ^2.1.0 # Missing: web & mac & windows & linux geolocator: ^9.0.2 # Missing: linux get: ^4.6.5 get_it: ^7.6.0 go_router: ^10.0.0 google_fonts: ^4.0.3 http_parser: ^4.0.2 image: ^4.0.17 image_cropper: ^3.0.3 # Missing: mac & windows & linux image_picker: ^1.0.1 intl: ^0.18.0 json_annotation: ^4.8.1 just_the_tooltip: ^0.0.12 # mime: ^1.0.4 # mutex: ^3.0.1 # path: ^1.8.2 # path_provider: ^2.0.13 # Missing: web permission_handler: ^10.4.2 # Missing: web & mac & linux # phone_number: ^1.0.0 # Missing: web & mac & windows & linux pinput: ^3.0.1 # retrofit: ^3.3.1 # shimmer: ^2.0.0 # swipeable_tile: ^2.0.0+3 # tap_debouncer: ^2.0.2 # universal_io: ^2.2.0 # Missing: web # uuid: ^3.0.7 video_compress: ^3.1.2 # Missing: web & windows & linux # video_player: ^2.6.1 # Missing: mac & windows & linux # wakelock: ^0.6.2 # Missing: linux webview_flutter: ^4.2.2 # Missing: web & mac & windows & linux # scroll_to_index: ^3.0.1 # sqflite: ^2.2.8+4 # Missing: web & windows & linux # listentocontacts: ^0.0.1+5 # Missing: web & mac & windows & linux qr_flutter: ^4.1.0 qr_code_scanner: ^1.0.1 another_flushbar: ^1.12.30 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.5 pretty_dio_logger: ^1.3.1 flutter_cache_manager: ^3.3.1 url_launcher: ^6.1.12 audioplayers: ^5.0.0 swipeable_tile: ^2.0.0+3 flutter_vibrate: ^1.3.0 envied: ^0.3.0+3 flutter_quill: 7.3.0 ## Media_kit media_kit: ^1.1.5 # Primary package. media_kit_video: ^1.1.6 # For video rendering. media_kit_native_event_loop: ^1.0.7 # Support for higher number of concurrent instances & better performance. media_kit_libs_android_video: ^1.3.2 # Android package for video native libraries. media_kit_libs_ios_video: ^1.1.3 # iOS package for video native libraries. media_kit_libs_macos_video: ^1.1.3 # macOS package for video native libraries. media_kit_libs_windows_video: ^1.0.7 # Windows package for video native libraries. media_kit_libs_linux: ^1.1.1 # GNU/Linux dependency package. mime: ^1.0.4 audio_waveforms: ^1.0.4 audio_session: ^0.1.16 # ffmpeg_kit_flutter: ^5.1.0 scroll_to_index: ^3.0.1 giphy_get: ^3.3.1 focused_menu: git: https://github.com/retroportalstudio/focused_menu.git open_file: ^3.3.2 flutter_animate: ^4.2.0+1 dio_smart_retry: ^5.0.0 flutter_mute: ^0.0.4 flutter_app_badger: ^1.5.0 # Missing: web & windows & linux dev_dependencies: flutter_test: sdk: flutter build_runner: ^2.4.6 flutter_gen_runner: ^5.3.1 json_serializable: ^6.7.1 retrofit_generator: ^7.0.8 envied_generator: ^0.3.0+3 riverpod_lint: ^2.0.4 custom_lint: ^0.5.3 flutter_lints: ^2.0.3 flutter_gen: output: lib/config/gen integrations: flutter_svg: true flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true assets: - assets/images/ - assets/icons/ - assets/sounds/ - assets/lottie/ - assets/videos/ - assets/service_account.json # To add assets to your application, add an assets section, like this: # assets: # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware # For details regarding adding assets from package dependencies, see # https://flutter.dev/assets-and-images/#from-packages # To add custom fonts to your application, add a fonts section here, # in this "flutter" section. Each entry in this list should have a # "family" key with the font family name, and a "fonts" key with a # list giving the asset and other descriptors for the font. For # example: # fonts: # - family: Schyler # fonts: # - asset: fonts/Schyler-Regular.ttf # - asset: fonts/Schyler-Italic.ttf # style: italic # - family: Trajan Pro # fonts: # - asset: fonts/TrajanPro.ttf # - asset: fonts/TrajanPro_Bold.ttf # weight: 700 # # For details regarding fonts from package dependencies, # see https://flutter.dev/custom-fonts/#from-packages ```
Service ```dart // ignore_for_file: avoid_print import 'dart:async'; import 'dart:io'; import 'package:collection/collection.dart'; import 'package:fimber/fimber.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:intune_app/config/res/app_strings.dart'; import 'package:intune_app/firebase_options.dart'; import 'package:intune_app/utils/notifications/exceptions.dart'; import 'package:intune_app/utils/notifications/handlers/call_notification_handler.dart'; import 'package:intune_app/utils/notifications/handlers/chat_message_notification_handler.dart'; import 'package:intune_app/utils/notifications/handlers/event_notification_handler.dart'; enum PayloadType { chat, call, event, // TODO: More types of notifications // projectPost, unknown, } /// On background notification handler /// All string must be hard coded in this callback. @pragma('vm:entry-point') Future listenToBackground(RemoteMessage message) async { print('listenToBackground: ${message.messageId}'); User user; try { user = await checkIfUserSignedIn(); } catch (e) { print('e: $e'); return; } await setupFlutterNotifications(); await showFlutterNotification(message); print('Handling a background message ${message.messageId}'); final handlers = [ const ChatMessageNotificationHandler(), const CallNotificationHandler(), const EventNotificationHandler(), ]; final handler = handlers.firstWhereOrNull( (element) => element.canHandle(message), ); if (handler == null) { print('handler not found'); return; } handler.handleBackground(user, message); } late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; Future checkIfUserSignedIn() async { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); final User? user = FirebaseAuth.instance.currentUser; if (user == null) { throw const UserNotSignedInException(); } return user; } /// On foreground notification handler Future onForgroundMessage(RemoteMessage message) async { Fimber.d('onForgroundMessage: ${message.messageId}'); User user; try { user = await checkIfUserSignedIn(); } catch (e) { print('e: $e'); return; } final handlers = [ const ChatMessageNotificationHandler(), const CallNotificationHandler(), const EventNotificationHandler(), ]; final handler = handlers.firstWhereOrNull( (element) => element.canHandle(message), ); if (handler == null) { print('handler not found'); return; } handler.handleForground(user, message); } Future onNotificationPressed(RemoteMessage message) async { print('onNotificationPressed: ${message.messageId}'); User user; try { user = await checkIfUserSignedIn(); } catch (e) { print('e: $e'); return; } final handlers = [ const ChatMessageNotificationHandler(), const CallNotificationHandler(), const EventNotificationHandler(), ]; final handler = handlers.firstWhereOrNull( (element) => element.canHandle(message), ); if (handler == null) { print('handler not found'); return; } handler.handleForground(user, message); } Future showFlutterNotification(RemoteMessage message) async { RemoteNotification? notification = message.notification; AndroidNotification? android = message.notification?.android; if (notification != null && android != null && !kIsWeb) { await flutterLocalNotificationsPlugin.show( notification.hashCode, notification.title, notification.body, NotificationDetails( android: AndroidNotificationDetails( channel.id, channel.name, channelDescription: channel.description, // TODO add a proper drawable resource to android, for now using // one that already exists in example app. icon: 'launch_background', ), ), ); } } late AndroidNotificationChannel channel; Future setupFlutterNotifications() async { channel = const AndroidNotificationChannel( 'high_importance_channel', // id 'High Importance Notifications', // title description: 'This channel is used for important notifications.', // description importance: Importance.high, ); flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); /// Create an Android Notification Channel. /// /// We use this channel in the `AndroidManifest.xml` file to override the /// default FCM channel to enable heads up notifications. if (Platform.isAndroid) { flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>() ?.createNotificationChannel(channel); } else if (Platform.isIOS) { flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< IOSFlutterLocalNotificationsPlugin>(); } /// Update the iOS foreground notification presentation options to allow /// heads up notifications. await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, ); } abstract class NotificationService { Future getDeviceToken(); Stream getDeviceTokenStream(); Future init(); void disconnect(); void dispose(); } class NotificationServiceimpl extends NotificationService { final _logger = FimberLog('NotificationService'); StreamSubscription? onForgroundMessageListener, onMessageOpenedAppListener; @override Future getDeviceToken() async { _logger.d('getDeviceToken'); return await FirebaseMessaging.instance.getToken(); } @override Stream getDeviceTokenStream() { return FirebaseMessaging.instance.onTokenRefresh; } Future _requestPermissions() async { _logger.d('requestPermissions'); final res = await FirebaseMessaging.instance.requestPermission( alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: true, sound: true, ); _logger.d('requestPermissions: ${res.authorizationStatus}'); return res.authorizationStatus == AuthorizationStatus.authorized; } @override Future init() async { _logger.d('init'); final hasPermission = await _requestPermissions(); if (!hasPermission) { return; } try { FirebaseMessaging.instance.setAutoInitEnabled(true); FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, ); _logger.d('init FlutterLocalNotificationsPlugin'); _setup(); FirebaseMessaging.onBackgroundMessage(listenToBackground); onForgroundMessageListener = FirebaseMessaging.onMessage.listen(onForgroundMessage); onMessageOpenedAppListener = FirebaseMessaging.onMessageOpenedApp.listen(onNotificationPressed); } catch (e, stk) { _logger.e('init: $e', ex: e, stacktrace: stk); } } void _setup() { const androidSettings = AndroidInitializationSettings('mipmap/launcher_icon'); final darwinSettings = DarwinInitializationSettings( requestAlertPermission: true, requestBadgePermission: true, requestSoundPermission: true, notificationCategories: [ DarwinNotificationCategory( AppStrings.notificationIOSCallCategoryId, actions: [ DarwinNotificationAction.plain( AppStrings.notificationActionAnswerCallId, AppStrings.notificationActionAnswerCallTitle, options: { DarwinNotificationActionOption.foreground, }, ), DarwinNotificationAction.plain( AppStrings.notificationActionDeclineCallId, AppStrings.notificationActionDeclineCallTitle, options: { DarwinNotificationActionOption.foreground, }, ), ], ), const DarwinNotificationCategory( AppStrings.calendar, ), ], ); final plugin = FlutterLocalNotificationsPlugin(); plugin.initialize( InitializationSettings( android: androidSettings, iOS: darwinSettings, macOS: darwinSettings, ), onDidReceiveNotificationResponse: (NotificationResponse details) { _logger .i('onDidReceiveNotificationResponse details = ${details.payload}'); }, ); // _logger.i('Requesting permissions'); // if (Platform.isAndroid) { // _plugin // .resolvePlatformSpecificImplementation< // AndroidFlutterLocalNotificationsPlugin>() // ?.requestPermission(); // } else if (Platform.isIOS) { // _plugin // .resolvePlatformSpecificImplementation< // IOSFlutterLocalNotificationsPlugin>() // ?.requestPermissions( // sound: true, // alert: true, // badge: true, // ); // } } @override void disconnect() { _logger.d('disconnect'); FirebaseMessaging.onBackgroundMessage((_) async {}); FirebaseMessaging.instance.setAutoInitEnabled(false); dispose(); onForgroundMessageListener?.cancel(); onMessageOpenedAppListener?.cancel(); } @override void dispose() { _logger.e('dispose'); } } ```
darshankawar commented 1 year ago

@hajajmaor Since the plugin example works that I also verified and at your end as well, it indicates it could be related to a config issue. Take a look at below related issues and see if it helps in your case or not.

https://github.com/firebase/flutterfire/issues/11286 https://github.com/firebase/flutterfire/issues/10603

hajajmaor commented 1 year ago

Find the bug. Server side Missed the data on the payload