我在应用程序处于前台时收到通知,但在应用程序处于后台时却未收到通知。此外,我有google-ed / StackOverflow-ed大约2个小时或更长时间,但能够解决此问题。
我的配置是:
firebase_auth: ^0.10.0
firebase_messaging: ^5.0.0
Run Code Online (Sandbox Code Playgroud)
清单是这样的:
代码是这样的:
final notifications = new FirebaseMessaging();
class AppNotifications {
static String fcmToken = '';
static Future<Null> init() async {
appLogs("AppNotifications init");
notifications.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true));
await configure();
fcmToken = await notifications.getToken();
appLogs("FCM TOKEN : " + fcmToken);
notifications.onTokenRefresh.listen((newToken) {
fcmToken = newToken;
appLogs("FCM TOKEN onTokenRefresh: " + fcmToken);
});
await updateFCMToken();
}
static Future<Null> configure() async {
appLogs("AppNotifications Configure");
notifications.configure(onMessage: (msg) {
appLogs('FCM onMessage: ' + msg.toString());
}, …
Run Code Online (Sandbox Code Playgroud)