Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Messaging: flutter firebase background notification not working for iOS #16878

Open
1 task done
MuhammedEminK opened this issue Dec 14, 2024 · 6 comments
Open
1 task done
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: ios Issues / PRs which are specifically for iOS. plugin: messaging type: bug Something isn't working

Comments

@MuhammedEminK
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Messaging

Which platforms are affected?

iOS

Description

I’m implementing Firebase Cloud Messaging (FCM) in my Flutter app to handle push notifications. However, I’ve encountered the following issue:

  • Foreground: Notifications are received and processed successfully.
  • Background or Terminated: Notifications are not received, and I can’t handle them.

I have looked all of the other questions and answers but I couldn't solve my problem even I try everything

Reproducing the issue

main.dart

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  print("Handling a background message: ${message.messageId}");

  // Firebase'i başlatın

  // Burada bildirimi işleyebilirsiniz
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,  // Firebase config dosyasını doğru şekilde eklediğinizden emin olun.
  );
  NotificationSettings settings = await FirebaseMessaging.instance.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false, // Zorunlu bildirim yerine geçici izni aktive eder
      sound: true,
    );

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  runApp(MyApp());
}

AppDelegate.swift

import UIKit
import Flutter
import Firebase
import FirebaseCore
import flutter_local_notifications


@main
@objc class AppDelegate: FlutterAppDelegate {
 override func application(
 _ application: UIApplication,
 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
 ) -> Bool {
// This is required to make any communication available in the action isolate.
 FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
 GeneratedPluginRegistrant.register(with: registry)
 }

 if #available(iOS 10.0, *) {
 UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
 }


 GeneratedPluginRegistrant.register(with: self)
 return super.application(application, didFinishLaunchingWithOptions: launchOptions)
 }

}

data

{
  "message": {
    "token": "",
    "data": {
      "receiver-id": "HBJq0SpqsrtoWjwIaH7kky14g4VZl53",
    },
    "notification": {
      "title": "Test Notification",
      "body": "This is a test message",
    },
    "apns": {
      "headers": {
        "apns-priority": "10"
      },
    "payload": {
        "aps": {
        "content-available": 1
        }
  }
    }
  }
}

info.plist

<?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>CADisableMinimumFrameDurationOnPhone</key>
	<true/>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleDisplayName</key>
	<string>Snapstory</string>
	<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>snapstory</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>com.googleusercontent...</string>
			</array>
		</dict>
	</array>
	<key>CFBundleVersion</key>
	<string>$(FLUTTER_BUILD_NUMBER)</string>
	<key>FirebaseAppDelegateProxyEnabled</key>
	<false/>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>NSCameraUsageDescription</key>
	<string>Image Picker</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>Image Picker</string>
	<key>NSPhotoLibraryUsageDescription</key>
	<string>Image Picker</string>
	<key>UIApplicationSupportsIndirectInputEvents</key>
	<true/>
	<key>NSPhotoLibraryAddUsageDescription</key>
	<string>Fotoğraf kütüphanesine fotoğraf kaydetmek için izin gerekiyor.</string>
	<key>UISupportsDocumentBrowser</key>
	<true/>
	<key>UIBackgroundModes</key>
	<array>
		<string>processing</string>
		<string>fetch</string>
		<string>remote-notification</string>
	</array>
	<key>BGTaskSchedulerPermittedIdentifiers</key>
	<array>
		<string>dev.flutter.background.refresh</string>
	</array>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
</dict>
</plist>

I try

<key>FirebaseAppDelegateProxyEnabled</key>
<false/>

but not work

Firebase Core version

3.8.0

Flutter Version

3.24.5

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
Dart SDK 3.5.4
Flutter SDK 3.24.5
snapstory 1.0.0+1

dependencies:
- awesome_notifications 0.10.0 [flutter flutter_web_plugins plugin_platform_interface intl]
- cloud_firestore 5.5.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cupertino_icons 1.0.8
- dio 5.7.0 [async http_parser meta path dio_web_adapter]
- firebase_auth 5.3.4 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 3.8.1 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 15.1.6 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 12.3.7 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_background_service 5.0.10 [flutter flutter_background_service_platform_interface flutter_background_service_android flutter_background_service_ios]
- flutter_broadcasts 0.4.0 [flutter]
- flutter_local_notifications 18.0.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- home_widget 0.7.0 [flutter path_provider path_provider_foundation]
- image_cropper 8.0.2 [flutter image_cropper_platform_interface image_cropper_for_web]
- image_picker 1.1.2 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows]
- intl 0.19.0 [clock meta path]
- path_provider 2.1.5 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- permission_handler 11.3.1 [flutter meta permission_handler_android permission_handler_apple permission_handler_html permission_handler_windows permission_handler_platform_interface]
- pro_image_editor 6.1.6 [flutter emoji_picker_flutter http image mime vibration]
- rxdart 0.28.0
- shared_preferences 2.3.3 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]

dev dependencies:
- flutter_lints 5.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]

transitive dependencies:
- _flutterfire_internals 1.3.47 [collection firebase_core firebase_core_platform_interface flutter meta]
- archive 3.6.1 [crypto path]
- args 2.6.0
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- characters 1.3.0
- clock 1.1.1
- cloud_firestore_platform_interface 6.5.1 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 4.3.5 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins]
- collection 1.18.0
- cross_file 0.3.4+2 [meta web]
- crypto 3.0.6 [typed_data]
- dbus 0.7.10 [args ffi meta xml]
- device_info_plus 11.1.1 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta web win32 win32_registry]
- device_info_plus_platform_interface 7.0.1 [flutter meta plugin_platform_interface]
- dio_web_adapter 2.0.0 [dio http_parser meta web]
- emoji_picker_flutter 3.1.0 [flutter flutter_web_plugins plugin_platform_interface shared_preferences web]
- fake_async 1.3.1 [clock collection]
- ffi 2.1.3
- file 7.0.1 [meta path]
- file_selector_linux 0.9.3+2 [cross_file file_selector_platform_interface flutter]
- file_selector_macos 0.9.4+2 [cross_file file_selector_platform_interface flutter]
- file_selector_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface]
- file_selector_windows 0.9.3+3 [cross_file file_selector_platform_interface flutter]
- firebase_auth_platform_interface 7.4.10 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.13.5 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web]
- firebase_core_platform_interface 5.3.1 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.18.2 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_messaging_platform_interface 4.5.49 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.9.5 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins meta web]
- firebase_storage_platform_interface 5.1.34 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.10.6 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http meta web]
- flutter_background_service_android 6.2.7 [flutter flutter_background_service_platform_interface]
- flutter_background_service_ios 5.0.3 [flutter flutter_background_service_platform_interface]
- flutter_background_service_platform_interface 5.1.2 [flutter platform plugin_platform_interface]
- flutter_local_notifications_linux 5.0.0 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 8.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.23 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- http 1.2.2 [async http_parser meta web]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image 4.3.0 [archive meta xml]
- image_cropper_for_web 6.0.2 [flutter flutter_web_plugins image_cropper_platform_interface web]
- image_cropper_platform_interface 7.0.0 [flutter plugin_platform_interface http]
- image_picker_android 0.8.12+18 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 3.0.6 [flutter flutter_web_plugins image_picker_platform_interface mime web]
- image_picker_ios 0.8.12+1 [flutter image_picker_platform_interface]
- image_picker_linux 0.2.1+1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_macos 0.2.1+1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface]
- image_picker_platform_interface 2.10.0 [cross_file flutter http plugin_platform_interface]
- image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface]
- leak_tracker 10.0.5 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.5 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 5.0.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- meta 1.15.0
- mime 2.0.0
- path 1.9.0
- path_provider_android 2.2.14 [flutter path_provider_platform_interface]
- path_provider_foundation 2.4.0 [flutter path_provider_platform_interface]
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface]
- permission_handler_android 12.0.13 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.4.5 [flutter permission_handler_platform_interface]
- permission_handler_html 0.1.3+5 [flutter flutter_web_plugins permission_handler_platform_interface web]
- permission_handler_platform_interface 4.2.3 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.2.1 [flutter permission_handler_platform_interface]
- petitparser 6.0.2 [meta]
- platform 3.1.6
- plugin_platform_interface 2.1.8 [meta]
- shared_preferences_android 2.3.4 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.5.3 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.4.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.4.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.4.2 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- shared_preferences_windows 2.4.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- sky_engine 0.0.99
- source_span 1.10.0 [collection path term_glyph]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.2 [async]
- string_scanner 1.2.0 [source_span]
- term_glyph 1.2.1
- test_api 0.7.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- timezone 0.10.0 [http path]
- typed_data 1.4.0 [collection]
- vector_math 2.1.4
- vibration 2.0.1 [flutter vibration_platform_interface]
- vibration_platform_interface 0.0.2 [flutter plugin_platform_interface device_info_plus]
- vm_service 14.2.5
- web 1.1.0
- win32 5.9.0 [ffi]
- win32_registry 1.1.5 [ffi win32]
- xdg_directories 1.1.0 [meta path]
- xml 6.5.0 [collection meta petitparser]

Additional context and comments

How can I fix it?

@MuhammedEminK MuhammedEminK added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Dec 14, 2024
@SelaseKay SelaseKay added plugin: messaging platform: ios Issues / PRs which are specifically for iOS. labels Dec 16, 2024
@SelaseKay
Copy link
Contributor

Duplicate of #16853

@SelaseKay SelaseKay marked this as a duplicate of #16853 Dec 16, 2024
@SelaseKay SelaseKay added resolution: duplicate This issue or pull request already exists and removed Needs Attention This issue needs maintainer attention. labels Dec 16, 2024
@MuhammedEminK
Copy link
Author

Duplicate of #16853

has this error been resolved?

@SelaseKay SelaseKay reopened this Dec 17, 2024
@SelaseKay
Copy link
Contributor

SelaseKay commented Dec 17, 2024

Hi @MuhammedEminK, apologies for linking the wrong issue earlier. This issue was raised recently and seems to have been resolved. I'm unable to reproduce this issue on my end with the current firebase_messaging example app. For reference, here’s a similar issue: #13442.

@SelaseKay SelaseKay added Needs Attention This issue needs maintainer attention. blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed resolution: duplicate This issue or pull request already exists Needs Attention This issue needs maintainer attention. labels Dec 17, 2024
@carlosandrercouto
Copy link

any update ?

@Danish-Git
Copy link

I am also facing same issue. I am also not able to receive notifications on iOS.

@kangmyonggyu
Copy link

kangmyonggyu commented Dec 20, 2024

Many people are saying that this issue can't be resolved, but it's been over two months and it's still not fixed.

I wonder what the Flutter team is doing about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: ios Issues / PRs which are specifically for iOS. plugin: messaging type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants