[英]Flutter FirebaseMessaging setup
In initState()
of the _PushMessagingExampleState
class in the example app for Flutter firebase_messaging 6.0.13, _firebaseMessaging.configure
is called first, followed by _firebaseMessaging.requestNotificationPermissions
.在 Flutter firebase_messaging 6.0.13 示例应用程序中
_PushMessagingExampleState
类的initState()
中, _firebaseMessaging.configure
调用 _firebaseMessaging.configure , _firebaseMessaging.configure
调用_firebaseMessaging.requestNotificationPermissions
。
However, in the firebase_messaging 6.0.13 API reference for the FirebaseMessaging class, the first thing it states is:但是,在FirebaseMessaging类的 firebase_messaging 6.0.13 API 参考中,它声明的第一件事是:
Your app should call requestNotificationPermissions first and then register handlers for incoming messages with configure.
您的应用应首先调用 requestNotificationPermissions,然后使用 configure 为传入消息注册处理程序。
Which is correct?哪个是正确的?
I'm guessing the API reference is correct and the example app could be improved?我猜 API 参考是正确的,示例应用程序可以改进吗?
Technically it doesn't matter but I have it set up as request permissions first, then configure.从技术上讲,这无关紧要,但我先将其设置为请求权限,然后再进行配置。 As an example of a working app:
作为一个工作应用程序的例子:
configureFcm() {
if (!isConfigured) {
if (Platform.isIOS) {
_fcm.onIosSettingsRegistered.listen((IosNotificationSettings data) {
});
_fcm.requestNotificationPermissions(IosNotificationSettings(sound: true, badge: true, alert: true));
}
_fcm.configure(
// in foreground
onMessage: (Map<String, dynamic> message) async {
_handleNotification(message);
},
// onBackgroundMessage: (Map<String, dynamic> message) async {
// print('on background message $message');
// },
// in background
onResume: (Map<String, dynamic> message) async {
_handleNotification(message);
},
// terminated
onLaunch: (Map<String, dynamic> message) async {
_handleNotification(message);
},
);
isConfigured = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.