feat: Enhance APNS token retrieval with retries and add cancel functionality to revert changes in notification and privacy settings.
This commit is contained in:
@@ -123,11 +123,18 @@ class PushNotificationService {
|
||||
|
||||
Future<void> _getAndRegisterToken() async {
|
||||
try {
|
||||
// On iOS, wait for APNS token before requesting FCM token
|
||||
// On iOS, wait for APNS token before requesting FCM token.
|
||||
// Apple may not deliver it immediately — retry a few times.
|
||||
if (Platform.isIOS) {
|
||||
final apnsToken = await _messaging!.getAPNSToken();
|
||||
String? apnsToken;
|
||||
for (int attempt = 0; attempt < 5; attempt++) {
|
||||
apnsToken = await _messaging!.getAPNSToken();
|
||||
if (apnsToken != null) break;
|
||||
debugPrint('[FCM] APNS token not available yet, retrying in ${attempt + 1}s...');
|
||||
await Future.delayed(Duration(seconds: attempt + 1));
|
||||
}
|
||||
if (apnsToken == null) {
|
||||
debugPrint('[FCM] APNS token not available yet (iOS simulator?), skipping FCM token registration');
|
||||
debugPrint('[FCM] APNS token not available after retries (simulator?), skipping FCM token registration');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user