28 lines
830 B
Dart
28 lines
830 B
Dart
import 'package:aitrainer_app/service/logging.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
|
|
class PushNotificationsManager with Logging {
|
|
PushNotificationsManager._();
|
|
|
|
factory PushNotificationsManager() => _instance;
|
|
|
|
static final PushNotificationsManager _instance = PushNotificationsManager._();
|
|
|
|
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
|
bool _initialized = false;
|
|
|
|
Future<void> init() async {
|
|
if (!_initialized) {
|
|
// For iOS request permission first.
|
|
_firebaseMessaging.requestNotificationPermissions();
|
|
_firebaseMessaging.configure();
|
|
|
|
// For testing purposes log the Firebase Messaging token
|
|
String token = await _firebaseMessaging.getToken();
|
|
log("FirebaseMessaging token: $token");
|
|
|
|
_initialized = true;
|
|
}
|
|
}
|
|
}
|