Closed downhamd closed 1 year ago
Thanks for the report @downhamd There was a similar recent issue https://github.com/firebase/flutterfire/issues/9822 reported which, according to OP and another commenter, got resolved after upgrading to 3.3.7 and Xcode to 14.1, but looking at the details you shared, you already seem to be on same config.
Is this only happening on iOS simulator or physical device too ?
I am facing this issue also, and I did as same as in #9822 but it still does not work.
This happened to me after upgrading flutter from 3.3.6
to 3.3.7
, and after upgrading Xcode from 14.0.1
to 14.1
.
flutter doctor -v
log:
flutter pub deps -- --style=compact
log:
Hi @darshankawar. I can confirm that this is only happening on the iOS emulator. On the Android emulator there is no error message after subscribing to topics. And push notifications work fine on physical devices for both iOS and Android.
Thanks for the update @downhamd
From the code sample you provided, you seem to be using third party plugins such as provider
. If possible, please provide complete minimal code sample without any third party plugin code that still triggers the error, so that we can use it to verify the reported behavior.
I tried the official plugin example and ran it on simulator with latest plugin versions and didn't get the issue.
No problem @darshankawar , I have removed the dependence on provider and simplified the code:
List<String> notificationTopics = [
'topic1',
'topic2',
'topic3',
];
Future<void> requestMessagingPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
print('User granted permission: ${settings.authorizationStatus}');
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted notifiactions permission');
messaging.getToken().then((token) async {
print('Messaging token: $token');
//configure notification topics
//gets a list of strings (topic names) from provider and loops through them to subscribe to them all
//subscribes to topics
for (var topic in notificationTopics) {
print('topic subscribing... $topic');
try {
await messaging.subscribeToTopic(topic).then((value) => print('topic subscribed: $topic'));
} catch (e) {
print('subscription error: $e');
}
}
});
}
}
Thanks for the update. I tried the same using plugin example and by subscribing to topic, I was able to successfully susbscribe it running on iOS simulator:
Syncing files to device iPhone 13 Pro...
flutter: Token monitor set null
flutter: FCM Token: cqmTvKvW_UCss1_YEatfwU:APA91bGA4lddsZJs-DhC9-6-R-mWuRM2hrGV-n2-IdKlUydRqcSMI2JXtUwVYi6pgK-WJgLu-IMF3ILU9Pb012xLuv-IiVKx-qheVl8ELRkKixXYdnzfGxkw4UaS9BWqZkO6ly2b1erL
flutter: Token monitor set null
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test".
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test" successful.
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test".
flutter: FlutterFire Messaging Example: Subscribing to topic "fcm_test" successful.
But looking at the frequency of such issues like this and also below, I am keeping this issue open and labeling for further insights from the team.
https://github.com/firebase/flutterfire/issues/9822 https://github.com/firebase/flutterfire/issues/9878
/cc @russellwheatley
tested using the following in main.dart
:
// ignore_for_file: require_trailing_commas
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
Future<void> requestMessagingPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
print('User granted permission: ${settings.authorizationStatus}');
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted notifiactions permission');
final token = await messaging.getToken();
print('Messaging token: $token');
//subscribe to topics
for (final topic in ['some', 'new', 'topics']) {
print('topic subscribing... $topic');
try {
await messaging
.subscribeToTopic(topic)
.then((value) => print('topic subscribed: $topic'));
} catch (e) {
print('subscription error: $e');
}
}
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Testing Something'),
),
body: ElevatedButton(
onPressed: () async {
await requestMessagingPermission();
},
child: const Text('press me'),
)),
);
}
}
Got the following console results:
2023-02-16 13:37:48.660351+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: User granted permission: AuthorizationStatus.authorized
2023-02-16 13:37:48.660413+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: User granted notifiactions permission
2023-02-16 13:37:50.169431+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribing... some
2023-02-16 13:37:50.999551+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribed: some
2023-02-16 13:37:50.999794+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribing... new
2023-02-16 13:37:51.201856+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribed: new
2023-02-16 13:37:51.202186+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribing... topics
2023-02-16 13:37:51.516142+0000 Firebase Cloud Messaging Example[18719:8105850] flutter: topic subscribed: topics
flutter doctor:
[✓] Flutter (Channel stable, 3.7.3, on macOS 12.5.1 21G83 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Community Edition (version 2020.1.1)
[✓] VS Code (version 1.75.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
There's something wrong with your setup. I'm guessing something to do with method swizzling. Read the documentation here to see if this is your issue.
Hey @downhamd. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@downhamd if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
Bug report
Describe the bug
I am getting the following error when I try to subscribe to topics:
Here is my function which is meant to obtain permissions for push notifications, then gets the token and subscribes to a list of topics...
I am getting the same error in the console for every topic that is being looped through and subscribed to. The weird thing is that push notifications were working before, but now they don't seem to be.
I have tried updating Flutter to the latest version (3.3.7), I have tried updating both the Firebase Core package (2.1.1) and the Firebase messaging package to their latest versions (14.0.4) and I am still getting the error.
What is this
token
that is missing? ThesubscribeToTopic()
function only seems to take the topic name string. Am I missing something?I have looked around for answers and haven't found much, some say that it may be to do with an xCode update, that is a possibility I suppose. Some have said that it may be to do with leaving a small amount of time like 1 second between getting the token and subscribing to topics. Is there anything that could be pointing to those?
Similar and possibly related to this or this?
Thank you very much, any help will be greatly appreciated.
Steps to reproduce
Steps to reproduce the behavior:
firebase_messaging
plugin to your flutter projectExpected behavior
I expect to be able to loop through a list of topic names and be able to subscribe to each topic.
Flutter doctor
Run
flutter doctor
and paste the output below:Click To Expand
``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-arm, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS (Xcode 14.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.1) [✓] VS Code (version 1.73.0) [✓] Connected device (3 available) [✓] HTTP Host Availability • No issues found! ```Flutter dependencies
Run
flutter pub deps -- --style=compact
and paste the output below:Click To Expand
``` Dart SDK 2.18.4 Flutter SDK 3.3.7 dependencies: - auto_orientation 2.2.1 [flutter] - cached_network_image 3.2.1 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cupertino_icons 1.0.4 - firebase_core 2.1.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.0.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - flash 2.0.3+2 [flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_inappwebview 5.4.3+7 [flutter] - flutter_linkify 5.0.2 [flutter linkify] - flutter_secure_storage 5.0.2 [meta flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows] - flutter_svg 1.0.3 [flutter meta path_drawing vector_math xml] - http 0.13.4 [async http_parser meta path] - image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface] - jwt_decoder 2.0.1 - mobile_scanner 1.1.0 [flutter flutter_web_plugins js] - provider 6.0.3 [collection flutter nested] - sentry_flutter 6.6.1 [flutter flutter_web_plugins sentry package_info_plus meta] - url_launcher 6.1.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - video_player 2.4.7 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] dev dependencies: - change_app_package_name 1.1.0 - flutter_launcher_icons 0.9.2 [args image path yaml] - flutter_lints 1.0.4 [lints] - flutter_native_splash 1.3.3 [args image meta path xml yaml universal_io] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] transitive dependencies: - _flutterfire_internals 1.0.7 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.1.8 [crypto path] - args 2.3.0 - async 2.9.0 [collection meta] - boolean_selector 2.1.0 [source_span string_scanner] - cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.2.1 - charcode 1.3.1 - clock 1.1.1 - cloud_firestore_platform_interface 5.8.4 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.0.4 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.16.0 - cross_file 0.3.3+1 [js meta] - crypto 3.0.1 [collection typed_data] - csslib 0.17.1 [source_span] - fake_async 1.3.1 [clock collection] - ffi 1.1.2 - file 6.1.2 [meta path] - firebase_core_platform_interface 4.5.2 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.0.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 4.2.5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.5 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - 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.5 [flutter] - flutter_secure_storage_linux 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 1.1.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.0 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.0.2 [flutter flutter_web_plugins flutter_secure_storage_platform_interface js] - flutter_secure_storage_windows 1.1.2 [flutter flutter_secure_storage_platform_interface] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - html 0.15.0 [csslib source_span] - http_parser 4.0.0 [charcode collection source_span string_scanner typed_data] - image 3.1.1 [archive meta xml] - image_picker_android 0.8.4+13 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface] - image_picker_ios 0.8.5+4 [flutter image_picker_platform_interface] - image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface] - js 0.6.4 - linkify 4.1.0 - lints 1.0.1 - matcher 0.12.12 [stack_trace] - material_color_utilities 0.1.5 - meta 1.8.0 - nested 1.0.0 [flutter] - octo_image 1.0.2 [flutter flutter_blurhash] - package_info_plus 1.4.2 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web] - package_info_plus_linux 1.0.5 [package_info_plus_platform_interface flutter path] - package_info_plus_macos 1.3.0 [flutter] - package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface] - package_info_plus_web 1.0.5 [flutter flutter_web_plugins http meta package_info_plus_platform_interface] - package_info_plus_windows 1.0.5 [package_info_plus_platform_interface ffi flutter win32] - path 1.8.2 - path_drawing 1.0.0 [vector_math meta path_parsing flutter] - path_parsing 1.0.0 [vector_math meta] - path_provider 2.0.10 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows] - path_provider_android 2.0.14 [flutter path_provider_platform_interface] - path_provider_ios 2.0.9 [flutter path_provider_platform_interface] - path_provider_linux 2.1.6 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_macos 2.0.6 [flutter path_provider_platform_interface] - path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface] - path_provider_windows 2.0.6 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - petitparser 4.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.3 [meta] - process 4.2.4 [file path platform] - rxdart 0.27.3 - sentry 6.6.1 [http meta stack_trace uuid] - sky_engine 0.0.99 - source_span 1.9.0 [collection path term_glyph] - sqflite 2.0.2+1 [flutter sqflite_common path] - sqflite_common 2.2.1+1 [synchronized path meta] - stack_trace 1.10.0 [path] - stream_channel 2.1.0 [async] - string_scanner 1.1.1 [source_span] - synchronized 3.0.0+2 - term_glyph 1.2.1 - test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0 [collection] - universal_io 2.0.4 [collection crypto meta typed_data] - url_launcher_android 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.0 [flutter plugin_platform_interface] - url_launcher_web 2.0.8 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface] - uuid 3.0.6 [crypto] - vector_math 2.1.2 - video_player_android 2.3.8 [flutter video_player_platform_interface] - video_player_avfoundation 2.3.4 [flutter video_player_platform_interface] - video_player_platform_interface 5.1.2 [flutter plugin_platform_interface] - video_player_web 2.0.6 [flutter flutter_web_plugins pedantic video_player_platform_interface] - win32 2.5.2 [ffi] - xdg_directories 0.2.0+1 [meta path process] - xml 5.3.1 [collection meta petitparser] - yaml 3.1.0 [collection source_span string_scanner] ```