Skip to content

Commit

Permalink
Catch and retry if getting Firebase Messing token failed (#869)
Browse files Browse the repository at this point in the history
Fixes #868
  • Loading branch information
nilsreichardt authored Sep 3, 2023
1 parent f7b9368 commit 0249d9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion app/lib/util/notification_token_adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'dart:developer';

import 'package:collection/collection.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:retry/retry.dart';
import 'package:sharezone/main/sharezone.dart';
import 'package:sharezone/util/api/user_api.dart';

Expand Down Expand Up @@ -59,7 +60,19 @@ class NotificationTokenAdderApi {
return null;
}

return _firebaseMessaging.getToken(vapidKey: vapidKey);
try {
// Retry because sometimes we get an unknown error from Firebase
// Messaging.
//
// See https://console.firebase.google.com/u/0/project/sharezone-c2bd8/crashlytics/app/ios:de.codingbrain.sharezone.app/issues/bd7d15551a69ad54ea806f4627d8eeda
return retry<String?>(
() => _firebaseMessaging.getToken(vapidKey: vapidKey),
maxAttempts: 3,
);
} catch (e, s) {
log('Could not get FCM token', error: e, stackTrace: s);
return null;
}
}

Future<void> tryAddTokenToDatabase(String token) async {
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ packages:
source: path
version: "0.0.1"
retry:
dependency: transitive
dependency: "direct main"
description:
name: retry
sha256: "822e118d5b3aafed083109c72d5f484c6dc66707885e07c0fbcb8b986bba7efc"
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ dependencies:
quiver: ^3.0.1
remote_configuration:
path: ../lib/remote_configuration
retry: ^3.1.2
rxdart: ^0.27.1
scrollable_positioned_list: ^0.3.8
share: ^2.0.4
Expand Down

0 comments on commit 0249d9e

Please sign in to comment.