feat: Enhance APNS token retrieval with retries and add cancel functionality to revert changes in notification and privacy settings.

This commit is contained in:
pradeepkumar
2026-03-20 02:48:41 +05:30
parent cbb9034424
commit 744787bae2
4 changed files with 81 additions and 7 deletions

View File

@@ -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;
}
}