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.63k stars 3.95k forks source link

[firebase_messaging] Disable Push Notifications permission pop up on iOS startup. #5897

Closed awaik closed 3 years ago

awaik commented 3 years ago

Bug report

This bug was described here https://github.com/FirebaseExtended/flutterfire/issues/4576 But I can't submit comments there.

Describe the bug Popup request for the Push notification permissions appears on the app start.

Steps to reproduce

Steps to reproduce the behavior:

Expected behavior

Popup request for the Push notification permissions have to appears only when we call the method

    if (Platform.isIOS) {
      NotificationSettings settings = await messaging.requestPermission(
        alert: true,
        announcement: false,
        badge: true,
        carPlay: false,
        criticalAlert: false,
        provisional: false,
        sound: true,
      );

Additional context

Add any other context about the problem here.


Flutter doctor

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [βœ“] Flutter (Channel stable, 2.0.5, on macOS 11.2 20D64 darwin-x64, locale en-RU) [βœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [βœ“] Xcode - develop for iOS and macOS [βœ“] Chrome - develop for the web [βœ“] Android Studio [βœ“] Android Studio (version 4.1) [βœ“] VS Code (version 1.55.2) [βœ“] Connected device (2 available) β€’ No issues found! ```

Flutter dependencies

Click To Expand ``` dependencies: - algolia 1.0.1 [meta http uuid] - async 2.5.0 [collection] - auto_size_text 3.0.0-nullsafety.0 [flutter] - better_player 0.0.62 [flutter cupertino_icons wakelock pedantic meta flutter_widget_from_html_core visibility_detector path_provider collection] - bubble 1.2.1 [flutter] - cached_network_image 3.0.0-nullsafety [flutter flutter_cache_manager octo_image] - cloud_firestore 1.0.1 [cloud_firestore_platform_interface cloud_firestore_web firebase_core firebase_core_platform_interface flutter meta] - crypto 3.0.0 [collection typed_data] - cupertino_icons 1.0.2 - file_picker 3.0.0 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface] - firebase_analytics 7.1.1 [firebase_analytics_platform_interface firebase_analytics_web firebase_core flutter meta] - firebase_auth 1.0.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 1.0.3 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 2.0.0 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_dynamic_links 0.8.0 [flutter firebase_core] - firebase_in_app_messaging 0.4.0 [meta flutter firebase_core] - firebase_messaging 9.0.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_storage 8.0.0 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_google_places 0.2.8 [flutter google_api_headers google_maps_webservice http rxdart listenable_stream collection] - flutter_keyboard_size 1.0.0+3 [flutter provider] - flutter_staggered_grid_view 0.4.0-nullsafety.3 [flutter] - flutter_svg 0.21.0-nullsafety.0 [flutter meta path_drawing vector_math xml] - flutter_swipe_action_cell 2.0.0 [flutter] - geoflutterfire 3.0.0-nullsafety.1 [flutter cloud_firestore rxdart] - get 4.0.0-nullsafety.2 [flutter] - google_sign_in 5.0.0 [google_sign_in_platform_interface google_sign_in_web flutter meta] - hive 2.0.2 [meta crypto] - hive_flutter 1.0.0 [flutter hive path_provider path] - http 0.13.0 [http_parser meta path pedantic] - image 3.0.1 [archive meta xml] - image_cropper 1.4.0 [flutter] - iphone_has_notch 1.0.0 [flutter] - json_annotation 4.0.1 - modal_progress_hud 0.1.3 [flutter] - package_info 2.0.0 [flutter] - photo_view 0.11.1 [flutter] - scrollable_positioned_list 0.2.0-nullsafety.0 [flutter collection] - sign_in_with_apple 3.0.0 [flutter meta] - snapping_sheet 3.0.0-nullsafety.0 [flutter] - supercharged 2.0.0 [supercharged_dart flutter] - uuid 3.0.3 [crypto] - video_compress 2.1.4 [flutter] - visibility_detector 0.2.0-nullsafety.1 [flutter] dev dependencies: - build_runner 1.11.5 [args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] - hive_generator 1.0.0 [build source_gen hive analyzer] - json_serializable 4.0.2 [analyzer build build_config json_annotation meta path source_gen] dependency overrides: - flutter_google_places 0.2.8 [flutter google_api_headers google_maps_webservice http rxdart listenable_stream collection] transitive dependencies: - _fe_analyzer_shared 14.0.0 [meta] - analyzer 0.41.2 [_fe_analyzer_shared args cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 3.1.2 [crypto path] - args 1.6.0 - boolean_selector 2.1.0 [source_span string_scanner] - build 1.6.2 [analyzer async convert crypto glob logging meta path] - build_config 0.4.6 [checked_yaml json_annotation meta path pubspec_parse yaml] - build_daemon 2.1.10 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 1.5.3 [analyzer build crypto graphs logging meta path package_config pool pub_semver] - build_runner_core 6.1.10 [async build build_config build_resolvers collection convert crypto glob graphs logging meta path package_config pedantic pool timing watcher yaml] - built_collection 5.0.0 - built_value 8.0.2 [built_collection collection fixnum] - characters 1.1.0 - charcode 1.2.0 - checked_yaml 1.0.4 [json_annotation source_span yaml] - cli_util 0.3.0 [meta path] - clock 1.1.0 - cloud_firestore_platform_interface 4.0.0 [collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 1.0.1 [cloud_firestore_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - code_builder 3.7.0 [built_collection built_value collection matcher meta] - collection 1.15.0 - convert 3.0.0 [typed_data] - csslib 0.17.0 [source_span] - dart_style 1.3.12 [analyzer args path pub_semver source_span] - fake_async 1.2.0 [clock collection] - ffi 1.0.0 - file 6.1.0 [meta path] - firebase 9.0.0 [http http_parser js] - firebase_analytics_platform_interface 1.1.0 [flutter meta] - firebase_analytics_web 0.2.0+1 [firebase firebase_analytics_platform_interface flutter flutter_web_plugins meta] - firebase_auth_platform_interface 4.0.0 [firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 1.0.2 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.0.0 [flutter meta plugin_platform_interface] - firebase_core_web 1.0.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.0.0 [collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 2.0.0 [firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 1.0.1 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 2.0.0 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 1.0.1 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - fixnum 1.0.0 - flutter_blurhash 0.5.4-nullsafety.0 [flutter meta pedantic] - flutter_cache_manager 3.0.0-nullsafety.1 [clock collection file flutter http image path path_provider pedantic rxdart sqflite uuid] - flutter_plugin_android_lifecycle 2.0.0 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math] - flutter_widget_from_html_core 0.6.0-rc.2021031201 [flutter html] - glob 2.0.1 [async collection file path pedantic string_scanner] - google_api_headers 1.0.0 [flutter package_info] - google_maps_webservice 0.0.20-nullsafety.4 [http meta json_annotation] - google_sign_in_platform_interface 2.0.1 [flutter meta quiver] - google_sign_in_web 0.10.0 [google_sign_in_platform_interface flutter flutter_web_plugins meta js] - graphs 0.2.0 - html 0.15.0 [csslib source_span] - http_multi_server 2.2.0 [async] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - intl 0.17.0 [clock path] - io 0.3.4 [charcode meta path string_scanner] - js 0.6.3 - listenable_stream 1.0.0 [rxdart flutter] - logging 1.0.1 - matcher 0.12.10 [stack_trace] - meta 1.3.0 - mime 0.9.7 - nested 1.0.0 [flutter] - octo_image 1.0.0-nullsafety.1 [flutter flutter_blurhash] - package_config 1.9.3 [path charcode] - path 1.8.0 - path_drawing 0.5.0-nullsafety.0 [vector_math meta path_parsing flutter] - path_parsing 0.2.0-nullsafety.0 [vector_math meta] - path_provider 2.0.1 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 2.0.0 [flutter] - path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface] - path_provider_windows 2.0.0 [path_provider_platform_interface meta path flutter ffi win32] - pedantic 1.11.0 - petitparser 4.0.2 [meta] - platform 3.0.0 - plugin_platform_interface 2.0.0 [meta] - pool 1.5.0 [async stack_trace] - process 4.1.0 [file path platform] - provider 5.0.0 [collection flutter nested] - pub_semver 2.0.0 [collection] - pubspec_parse 0.1.8 [checked_yaml json_annotation pub_semver yaml] - quiver 3.0.0 [matcher] - rxdart 0.26.0 - shelf 1.0.0 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 0.2.4+1 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_gen 0.9.10+3 [analyzer async build dart_style glob meta path pedantic source_span] - source_span 1.8.0 [charcode collection path term_glyph] - sqflite 2.0.0+2 [flutter sqflite_common path] - sqflite_common 2.0.0+2 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - stream_transform 2.0.0 - string_scanner 1.1.0 [charcode source_span] - supercharged_dart 2.0.0 - synchronized 3.0.0 - term_glyph 1.2.0 - test_api 0.2.19 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - timing 0.1.1+3 [json_annotation] - typed_data 1.3.0 [collection] - vector_math 2.1.0 - wakelock 0.4.0 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web] - wakelock_macos 0.1.0 [flutter flutter_web_plugins wakelock_platform_interface] - wakelock_platform_interface 0.2.0 [flutter meta] - wakelock_web 0.2.0 [flutter flutter_web_plugins js wakelock_platform_interface] - watcher 1.0.0 [async path pedantic] - web_socket_channel 1.2.0 [async crypto stream_channel] - win32 2.0.4 [ffi] - xdg_directories 0.2.0 [meta path process] - xml 5.0.2 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```

maxim-drobonoh commented 3 years ago

I have the same issue version firebase_messaging: ^8.0.0-dev.11

maxim-drobonoh commented 3 years ago

@awaik I have found the reason of this bug. You're probably using this lib flutter_local_notifications to show local push notifications, so it that's library ask notifications permissions when app launch

See documentation

//inititalization
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin()
await lutterLocalNotificationsPlugin.initializef(initializationSettings,
        onSelectNotification: selectNotification);
flutterLocalNotificationsPlugin.initialize() 
description 

/// Note that on iOS, initialisation may also request notification /// permissions where users will see a permissions prompt. This may be fine /// in cases where it's acceptable to do this when the application runs for /// the first time. However, if your application needs to do this at a later /// point in time, set the [IOSInitializationSettings.requestAlertPermission], /// [IOSInitializationSettings.requestBadgePermission] and /// [IOSInitializationSettings.requestSoundPermission] values to false. /// [IOSFlutterLocalNotificationsPlugin.requestPermissions] can then be called /// to request permissions when needed.

I hope it will help :)

martesabt commented 3 years ago

I got the same problem and @maxim-drobonoh answer solved it!

In my case I missed adding await on the flutter local notifications plugin initialize call.

Salakar commented 3 years ago

Closing due to this being an issue with flutter_local_notifications as pointed out above. FlutterFire messaging requestPermission only shows the popup when you explicitly call the method.