1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 16:26:27 +00:00
comunicmobile/lib/helpers/firebase_messaging_helper.dart

27 lines
771 B
Dart
Raw Normal View History

2021-04-15 11:34:49 +00:00
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
/// Firebase messaging helper
///
/// @author Pierre Hubert
bool _isFirebaseReady = false;
class FirebaseMessagingHelper {
/// Pre configure notifications
static Future<void> preConfigure() async {
if (!_isFirebaseReady) await Firebase.initializeApp();
_isFirebaseReady = true;
final settings = await FirebaseMessaging.instance.requestPermission();
if (settings.authorizationStatus != AuthorizationStatus.authorized)
throw new Exception("The user did not authorize notifications!");
}
/// Get a Firebase access token
static Future<String?> getToken() async {
2021-04-15 11:34:49 +00:00
return await FirebaseMessaging.instance.getToken();
}
}