firebase_messaging An unknown error has occurred. #13565
Unanswered
shijinthottiyil
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm encountering a problem while running flutter app on iOS devices. The app was working fine since yesterday (29/10/2024). While running the app on iOS simulator I'm getting this error [firebase_messaging/unknown] An unknown error has occurred. The app is working fine on android emulator.
I reconfigured firebase project but that doesn't seems to work.
CODE:
main.dart
//Adding Firebase to the Project for implementing push notifications.
import 'package:bluelin/features/auth/views/init_view.dart';
import 'package:bluelin/utils/logic/networking/networking.dart';
import 'package:bluelin/utils/logic/push_notification/push_notification_manager.dart';
import 'package:bluelin/utils/ui/constants/constants.dart';
import 'package:bluelin/utils/ui/widgets/v2/app_error_widget.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'firebase_options.dart';
void main() async {
try {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform);
await GetStorage.init();
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
await PushNotificationManager().initAndReceiveNotifications();
runApp(const MyApp());
} catch (error) {
logger.i(error.toString());
runApp(
ErrorApp(
error: error,
),
);
}
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@OverRide
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
scrollBehavior: const ScrollBehavior()
.copyWith(physics: const BouncingScrollPhysics()),
defaultTransition: Transition.fadeIn,
darkTheme: AppTheme.darkTheme,
themeMode: ThemeMode.dark,
home: const InitView(),
// initialBinding: DI(),
// home: TokenManager.contanisAccess()
// ? const BottomView()
// : const OnboardingScreen(),
);
}
}
// ErrorApp
class ErrorApp extends StatelessWidget {
const ErrorApp({super.key, this.error});
final dynamic error;
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: AppColors.kBlack,
body: AppErrorWidget(
message:
"We’re experiencing some issues on our end.\nMake sure you're connect to internet and try again.",
buttonName: 'Restart',
onButtonPress: () {
SystemNavigator.pop();
},
error: error,
),
),
);
}
}
push_notification_manager.dart
import 'dart:io';
import 'package:bluelin/utils/logic/push_notification/flutter_local_notifications_manager.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
///Top-Level Function for handling background Notifications.<--App is Terminated--->
///
Future handleBackgroundMessage(RemoteMessage message) async {
if (kDebugMode) {
print('Title = ${message.notification?.title}');
print('Body = ${message.notification?.body}');
print('Payload = ${message.data}');
}
await FlutterLocalNotificationsManager.showNotification(message);
}
///Class For Handling Firebase Notification Logic.
///
class PushNotificationManager {
final _firebaseMessaging = FirebaseMessaging.instance;
// variable to store fcm token.
static late final String? _fcmToken;
// getter to read fcmToken
static String? get fcmToken => _fcmToken;
Future initAndReceiveNotifications() async {
await _firebaseMessaging.requestPermission();
}
}
I think the issue is coming _fcmToken = await _firebaseMessaging.getToken(); this step.
Please help me fix this ASOP as i'm getting really close to deadline.
SIMULATOR SCREENSHOT
Beta Was this translation helpful? Give feedback.
All reactions