we are enabling push notification with firebase in our Flutter app, but it's returning this error on my real device when I want to sign in. I don't know where is the error, and it's happening only with IOS. Android has no problems. I have followed the official documentation, too. Xcode: 15.2, Flutter: 3.19.5
here is the error message:
FLTFirebaseMessaging: An error occurred while calling method Messaging#getToken, errorOrNil => {
NSErrorFailingURLKey = "https://device-provisioning.googleapis.com/checkin";
NSErrorFailingURLStringKey = "https://device-provisioning.googleapis.com/checkin";
NSLocalizedDescription = "The request timed out.";
"_NSURLErrorFailingURLSessionTaskErrorKey" = "LocalDataTask <9BEF5303-AEAA-4005-9A7D-D8307A35D3D5>.<1>";
"_NSURLErrorRelatedURLSessionTaskErrorKey" = (
"LocalDataTask <9BEF5303-AEAA-4005-9A7D-D8307A35D3D5>.<1>"
);
"_kCFStreamErrorCodeKey" = "-2103";
"_kCFStreamErrorDomainKey" = 4;
}
here is how I initialize the initFirebase code for token:
Future<void> initFirebase() async {
String? fcmToken;
await Firebase.initializeApp(
options: FirebaseOptions(
apiKey: Platform.isAndroid
? "AIzaSyBuRrD9IUg721orGNJzUPw_6jBqzW0qbgcw"
: "AIzaSyDpy26KbxDkillvYaBlX_lqvmXC1XOQSpA",
appId: Platform.isAndroid
? "1:199061089561:android:bc4deb3u87dd11a1af0d90"
: '1:199061089961:ios:09e1ew1avp141a86af0d90',
messagingSenderId: "199061680561",
iosBundleId: "com.flutter.truck",
storageBucket: "truck-19121.appspot.com",
projectId: "truck-19121"));
if (Platform.isAndroid) {
fcmToken = await FirebaseMessaging.instance.getToken();
} else if (Platform.isIOS) {
fcmToken = await FirebaseMessaging.instance.getAPNSToken();
if (fcmToken != null) {
await Future<void>.delayed(
const Duration(
seconds: 5,
),
);
fcmToken = await FirebaseMessaging.instance.getAPNSToken();
}
}
printColored("FCM USER TOKEN: $fcmToken", PrintedColors.red);
// FOREGROUND MESSAGE HANDLING.
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
debugPrint(
"NOTIFICATION FOREGROUND MODE: ${message.notification!.title} in foreground");
debugPrint("NOTIFICATION DATA: ${message.data} in terminated");
LocalNotificationService.localNotificationService
.showRemoteNotification(message);
});
// BACkGROUND MESSAGE HANDLING
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// FROM TERMINATED MODE
handleMessage(RemoteMessage message) {
debugPrint(
"NOTIFICATION FROM TERMINATED MODE: ${message.notification!.title} in terminated");
debugPrint("NOTIFICATION DATA: ${message.data} in terminated");
LocalNotificationService.localNotificationService
.showRemoteNotification(message);
}
RemoteMessage? remoteMessage =
await FirebaseMessaging.instance.getInitialMessage();
if (remoteMessage != null) {
handleMessage(remoteMessage);
}
FirebaseMessaging.onMessageOpenedApp.listen(handleMessage);
}
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
LocalNotificationService.localNotificationService
.showRemoteNotification(message);
debugPrint(
"NOTIFICATION BACKGROUND MODE: ${message.notification!.title} in background");
debugPrint("NOTIFICATION DATA: ${message.data} in terminated");
}
the solution was with Firebase installation sdk in my Xcode and integrate with the console