Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FirebaseMessagingService {
- static FirebaseMessaging? _firebaseMessaging;
- static FirebaseMessaging get firebaseMessaging => FirebaseMessagingService._firebaseMessaging ?? FirebaseMessaging.instance;
- final NotificationService notification = di.locator<NotificationService>();
- Future<void> initialize() async {
- if (Platform.isIOS) {
- NotificationSettings settings = await firebaseMessaging.requestPermission(
- alert: true,
- announcement: false,
- badge: true,
- carPlay: false,
- criticalAlert: false,
- provisional: false,
- sound: true,
- );
- if (settings.authorizationStatus == AuthorizationStatus.authorized) {
- log('User granted permission');
- } else if (settings.authorizationStatus == AuthorizationStatus.provisional) {
- log('User granted provisional permission');
- } else {
- log('User declined or has not accepted permission');
- }
- }
- FirebaseMessaging.onMessage.listen((RemoteMessage message) {
- if (message.data['source'] == 'Insider') {
- FlutterInsider.Instance.handleNotification(<String, dynamic>{"data": message.data});
- } else {
- notification.showNotificationFirebase(message);
- }
- log("onMessages: ${message.data.toString()}");
- });
- FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
- if (message.data['source'] == 'Insider') {
- FlutterInsider.Instance.handleNotification(<String, dynamic>{"data": message.data});
- } else {
- notification.showNotificationFirebase(message);
- }
- log("onLaunch: ${message.data}");
- });
- FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
- }
- Future<void> onRefreshFcmToken(BuildContext context) async {
- FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) async {
- Provider.of<MemberProvider>(context, listen: false).updateFcmToken(token: fcmToken);
- await Storage.save(deviceTokenStorageKey, fcmToken);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement