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.72k stars 3.98k forks source link

🐛 [firebase_dynamic_links] FirebaseDynamicLinks.instance.getInitialLink() always Null #10671

Closed davefaliskie closed 1 year ago

davefaliskie commented 1 year ago

Bug report

Describe the bug FirebaseDynamicLinks.instance.getInitialLink() Is always null in iOS when booting the app in release mode.

Steps to reproduce

Follow the documentation for setting up dynamic links and receiving dynamic links

Expected behavior

When the app is closed completely on iOS and the dynamic link is clicked, the app will open but not to the page expected. If the app was running in the background then FirebaseDynamicLinks.instance.onLink.listen is triggered and the page redirect can be handled.

I've seen several other bug reports with the same issue from years ago. None really give an answer and all essentially say this is fixed, but for me it's not.

Additional context

Below initDynamicLink is called from initState in the homePage view (main view of the app)

void initDynamicLink() async {
    // WORKS
    FirebaseDynamicLinks.instance.onLink.listen(
      (pendingLink) {
        final Uri deepLink = pendingLink.link;
        Sentry.captureMessage("listen deepLink: $deepLink");
        ref.read(goRouterProvider).push(deepLink.path);
      },
    );

    // DOES NOT WORK
    final linkData = await FirebaseDynamicLinks.instance.getInitialLink();
    final Uri? deepLink = linkData?.link;
    if (deepLink != null) {
      ref.read(goRouterProvider).push(deepLink.path);
    }

    Sentry.captureMessage("cold deepLink: $deepLink");
 }

I'm running in release mode on the physical device, Sentry will capture the onLink when the app was already running in the background, but for getInitialLink the deepLink is always null

Also the onLink.listen is never triggered if the link was clicked when the app was closed.

Flutter doctor

Click To Expand ``` [✓] Flutter (Channel stable, 3.7.7, on macOS 13.2.1 22D68 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc2) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.76.2) [✓] Connected device (4 available) [✓] HTTP Host Availability ```

Flutter dependencies

Click To Expand ``` Dart SDK 2.19.4 Flutter SDK 3.7.7 roads 1.0.0+2 dependencies: - audio_service 0.18.9 [audio_service_platform_interface audio_service_web audio_session rxdart flutter_cache_manager clock js flutter flutter_web_plugins] - audio_session 0.1.13 [flutter flutter_web_plugins rxdart meta] - cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - collection 1.17.0 - connectivity_plus 3.0.2 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm] - cross_file 0.3.3+2 [js meta] - cupertino_icons 1.0.5 - envied 0.3.0 - firebase_analytics 10.1.6 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_core 2.8.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_dynamic_links 5.0.17 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - flutter_colorpicker 1.0.3 [flutter] - flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - flutter_riverpod 2.1.3 [collection flutter meta riverpod state_notifier] - go_router 5.2.4 [collection flutter flutter_web_plugins logging meta] - google_sign_in 5.4.4 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - hive 2.2.3 [meta crypto] - hive_flutter 1.1.0 [flutter hive path_provider path] - http 0.13.5 [async http_parser meta path] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image_picker 0.8.6+1 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface] - image_picker_for_web 2.1.10 [flutter flutter_web_plugins image_picker_platform_interface] - intl 0.17.0 [clock path] - just_audio 0.9.31 [just_audio_platform_interface just_audio_web audio_session rxdart path path_provider async uuid crypto meta flutter] - mime 1.0.4 - modal_bottom_sheet 3.0.0-pre [flutter] - path_provider 2.0.12 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - permission_handler 10.2.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - record 4.4.4 [flutter record_platform_interface record_web record_windows record_macos record_linux] - rxdart 0.27.7 - sentry_flutter 6.22.0 [flutter flutter_web_plugins sentry package_info_plus meta] - share_plus 6.3.1 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi win32] - sign_in_with_apple 4.3.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web] - social_login_buttons 1.0.7 [flutter] - transparent_pointer 1.0.0 [flutter] - url_launcher 6.1.10 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_strategy 0.2.0 [flutter_web_plugins] - uuid 3.0.7 [crypto] dev dependencies: - build_runner 2.3.3 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - envied_generator 0.3.0 [envied build source_gen analyzer] - flutter_launcher_icons 0.11.0 [args checked_yaml cli_util image json_annotation path yaml] - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] - hive_generator 2.0.0 [build source_gen hive analyzer source_helper] transitive dependencies: - _fe_analyzer_shared 52.0.0 [meta] - _flutterfire_internals 1.0.18 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 5.4.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - archive 3.3.6 [crypto path pointycastle] - args 2.3.2 - async 2.10.0 [collection meta] - audio_service_platform_interface 0.1.0 [flutter plugin_platform_interface meta] - audio_service_web 0.1.1 [audio_service_platform_interface rxdart js flutter flutter_web_plugins] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.3.1 [analyzer async convert crypto glob logging meta path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - build_daemon 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel] - build_resolvers 2.1.0 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml] - build_runner_core 7.2.7 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml] - built_collection 5.1.1 - built_value 8.4.3 [built_collection collection fixnum meta] - cached_network_image_platform_interface 2.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.2 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.2.1 - checked_yaml 2.0.2 [json_annotation source_span yaml] - cli_util 0.3.5 [meta path] - clock 1.1.1 - code_builder 4.4.0 [built_collection built_value collection matcher meta] - connectivity_plus_platform_interface 1.2.3 [flutter meta plugin_platform_interface] - convert 3.1.1 [typed_data] - crypto 3.0.2 [typed_data] - dart_style 2.2.4 [analyzer args path pub_semver source_span] - dbus 0.7.8 [args ffi meta xml] - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.3.23 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.1+14 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_core_platform_interface 4.5.3 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.2.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_dynamic_links_platform_interface 0.2.3+32 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - fixnum 1.0.1 - flutter_blurhash 0.7.0 [flutter] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_plugin_android_lifecycle 2.0.7 [flutter] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - frontend_server_client 3.2.0 [async path] - glob 2.1.1 [async collection file path string_scanner] - google_sign_in_android 6.1.5 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.5.1 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.3.0 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.10.2+1 [flutter flutter_web_plugins google_sign_in_platform_interface js] - graphs 2.2.0 [collection] - http_multi_server 3.2.1 [async] - image 3.3.0 [archive meta xml] - image_picker_android 0.8.5+5 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_ios 0.8.6+6 [flutter image_picker_platform_interface] - image_picker_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface] - io 1.0.4 [meta path string_scanner] - js 0.6.5 [meta] - json_annotation 4.8.0 [meta] - just_audio_platform_interface 4.2.0 [flutter plugin_platform_interface] - just_audio_web 0.4.7 [just_audio_platform_interface flutter flutter_web_plugins] - lints 2.0.1 - logging 1.1.1 - matcher 0.12.13 [meta stack_trace] - material_color_utilities 0.2.0 - meta 1.8.0 - nm 0.5.0 [dbus] - octo_image 1.0.2 [flutter flutter_blurhash] - package_config 2.1.0 [path] - package_info_plus 3.0.3 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.2 - path_provider_android 2.0.22 [flutter path_provider_platform_interface] - path_provider_foundation 2.1.1 [flutter path_provider_platform_interface] - path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.5 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_android 10.2.0 [flutter permission_handler_platform_interface] - permission_handler_apple 9.0.7 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.9.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.2 [flutter permission_handler_platform_interface] - petitparser 5.1.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.3 [meta] - pointycastle 3.6.2 [collection convert js] - pool 1.5.1 [async stack_trace] - process 4.2.4 [file path platform] - pub_semver 2.1.3 [collection meta] - pubspec_parse 1.2.1 [checked_yaml collection json_annotation pub_semver yaml] - quiver 3.2.1 [matcher] - record_linux 0.4.1 [flutter record_platform_interface path] - record_macos 0.2.2 [flutter record_platform_interface] - record_platform_interface 0.5.0 [flutter plugin_platform_interface] - record_web 0.5.0 [flutter flutter_web_plugins record_platform_interface] - record_windows 0.7.1 [flutter record_platform_interface path] - riverpod 2.1.3 [collection meta stack_trace state_notifier] - sentry 6.22.0 [http meta stack_trace uuid intl] - share_plus_platform_interface 3.2.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid] - shelf 1.4.0 [async collection http_parser path stack_trace stream_channel] - shelf_web_socket 1.0.3 [shelf stream_channel web_socket_channel] - sign_in_with_apple_platform_interface 1.0.0 [flutter plugin_platform_interface meta] - sign_in_with_apple_web 1.0.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface js] - sky_engine 0.0.99 - source_gen 1.2.6 [analyzer async build dart_style glob meta path source_span yaml] - source_helper 1.3.3 [analyzer collection source_gen] - source_span 1.9.1 [collection path term_glyph] - sqflite 2.2.4+1 [flutter sqflite_common path] - sqflite_common 2.4.2+2 [synchronized path meta] - stack_trace 1.11.0 [path] - state_notifier 0.7.2+1 [meta] - stream_channel 2.1.1 [async] - stream_transform 2.1.0 - string_scanner 1.2.0 [source_span] - synchronized 3.0.1 - term_glyph 1.2.1 - test_api 0.4.16 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timing 1.0.1 [json_annotation] - typed_data 1.3.1 [collection] - url_launcher_android 6.0.24 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.1 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.3 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.3 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface] - url_launcher_web 2.0.15 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.4 [flutter url_launcher_platform_interface] - vector_math 2.1.4 - watcher 1.0.2 [async path] - web_socket_channel 2.3.0 [async crypto stream_channel] - win32 3.1.3 [ffi] - xdg_directories 0.2.0+3 [meta path process] - xml 6.2.2 [collection meta petitparser] - yaml 3.1.1 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

Thanks for the report @davefaliskie Can you take a look at this issue and underlying comments and see if they help in your case ?

davefaliskie commented 1 year ago

@darshankawar Unfortunately, no. I tried all the suggestions and I already had GoogleService-Info.plist setup & have tried updating, but the same issue is still there.

darshankawar commented 1 year ago

Thanks for the update. I am unable to replicate this using example app running in --release mode on iOS device. Can you take a look at that example ? also if it doesn't help, please provide a complete minimal reproducible code sample that we can use to verify this behavior.

davefaliskie commented 1 year ago

@darshankawar Thanks for looking, I was able to solve this. Here was my issue incase anyone else comes across this later.

I had setup Flutter deep links originally on the domain https://app.example.com and also had apple-app-site-association hosted at https://app.example.com/.well-known/apple-app-site-association

Then I was using https://app.example.com/links for my dynamic links, which I didn't think would be an issue. I had already set FlutterDeepLinkingEnabled = False in the info.plist based on the dynamic links docs about deep linking issues that could happen (setting FlutterDeepLinkingEnabled to false, by itself does not fix this issue).

When I changed my dynamic links to use a different subdomain & no additional path: https://link.example.com then everything worked as expected.

Further, deep links and dynamic links are now both working after enabling FlutterDeepLinkingEnabled & setting both urls as applinks: in xcode.