feat: Upgrade Firebase Functions dependencies, enhance notification service with APNS support and FCM
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:travel_mate/services/logger_service.dart';
|
||||
@@ -58,7 +59,26 @@ class NotificationService {
|
||||
|
||||
Future<String?> getFCMToken() async {
|
||||
try {
|
||||
return await _firebaseMessaging.getToken();
|
||||
if (Platform.isIOS) {
|
||||
String? apnsToken = await _firebaseMessaging.getAPNSToken();
|
||||
int retries = 0;
|
||||
while (apnsToken == null && retries < 3) {
|
||||
LoggerService.info(
|
||||
'Waiting for APNS token... (Attempt ${retries + 1}/3)',
|
||||
);
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
apnsToken = await _firebaseMessaging.getAPNSToken();
|
||||
retries++;
|
||||
}
|
||||
if (apnsToken == null) {
|
||||
LoggerService.error('APNS token not available after retries');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final token = await _firebaseMessaging.getToken();
|
||||
LoggerService.info('NotificationService - FCM Token: $token');
|
||||
return token;
|
||||
} catch (e) {
|
||||
LoggerService.error('Error getting FCM token: $e');
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user