Honestly, I have no idea why apple makes everything so complex and convoluted
I wrote a basic code to get the fcm token of the device in order to be able to send notifications//
Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:shared_preferences/shared_preferences.dart';
Future<String?> gettingFirebaseId() async {
try {
final prefs = await SharedPreferences.getInstance();
FirebaseMessaging messaging = FirebaseMessaging.instance;
// Request permission to receive notifications
NotificationSettings settings = await messaging.requestPermission(
alert: true,
badge: true,
sound: true,
);
switch (settings.authorizationStatus) {
case AuthorizationStatus.authorized:
case AuthorizationStatus.provisional:
prefs.setBool('hasRequestedNotificationPermission', true);
print('Notification Permission Granted');
break;
case AuthorizationStatus.denied:
print('Notification Permission Denied');
break;
case AuthorizationStatus.notDetermined:
print('Notification Permission Not Determined');
break;
}
// Attempt to get the device token regardless of the permission status
String? token = await messaging.getToken();
if (token != null) {
print('FCM Token: $token');
} else {
print('Failed to retrieve FCM Token');
}
return token;
} catch (e) {
print('Error getting FCM Token: $e');
return "fcm_token_not_found";
}
}
Its working fine on Android but not on iOS , anyone have any idea why. I have added the APN key to my firebase project.