1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/helpers/firebase_messaging_helper.dart

27 lines
771 B
Dart

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 {
return await FirebaseMessaging.instance.getToken();
}
}