parent
78056072d4
commit
ff6e4d58f7
@ -0,0 +1,21 @@
|
|||||||
|
package com.cakewallet.cake_wallet;
|
||||||
|
|
||||||
|
import io.flutter.app.FlutterApplication;
|
||||||
|
import io.flutter.plugin.common.PluginRegistry;
|
||||||
|
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
|
||||||
|
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||||
|
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
|
||||||
|
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
|
||||||
|
|
||||||
|
public class Application extends FlutterApplication implements PluginRegistrantCallback {
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
FlutterFirebaseMessagingService.setPluginRegistrant(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerWith(PluginRegistry registry) {
|
||||||
|
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict/>
|
<dict>
|
||||||
|
<key>aps-environment</key>
|
||||||
|
<string>development</string>
|
||||||
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:cake_wallet/main.dart';
|
||||||
|
import 'package:cake_wallet/utils/show_bar.dart';
|
||||||
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
|
|
||||||
|
class PushNotificationsService {
|
||||||
|
PushNotificationsService._();
|
||||||
|
|
||||||
|
factory PushNotificationsService() => _instance;
|
||||||
|
|
||||||
|
static final PushNotificationsService _instance = PushNotificationsService._();
|
||||||
|
static Future<dynamic> _onBackgroundMessage(Map<String, dynamic> message) async {}
|
||||||
|
final _firebaseMessaging = FirebaseMessaging();
|
||||||
|
bool _initialized = false;
|
||||||
|
|
||||||
|
Future<void> init() async {
|
||||||
|
if (_initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_firebaseMessaging.requestNotificationPermissions();
|
||||||
|
_firebaseMessaging.configure(
|
||||||
|
onMessage: (message) async {
|
||||||
|
Map<dynamic, dynamic> alert = {};
|
||||||
|
String msg = '';
|
||||||
|
String title = '';
|
||||||
|
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
alert = message['aps']['alert'] as Map<dynamic, dynamic> ?? <dynamic, dynamic>{};
|
||||||
|
msg = alert['body'] as String ?? '';
|
||||||
|
title = alert['title'] as String ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
msg = message['notification']['body'] as String ?? '';
|
||||||
|
title = message['notification']['title'] as String ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
await showBar<void>(navigatorKey.currentContext, msg, titleText: title, duration: null);
|
||||||
|
},
|
||||||
|
onBackgroundMessage: _onBackgroundMessage);
|
||||||
|
|
||||||
|
_initialized = true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue