Flutter onBackgroundMessage未被调用颤振消息
由于发送请求后应用程序处于后台时,Flutter onBackgroundMessage未被调用颤振消息,flutter,firebase-cloud-messaging,Flutter,Firebase Cloud Messaging,由于发送请求后应用程序处于后台时,onBackgroundmessage未被触发,我在我的颤振应用程序上使用firebase消息获得了一次令人沮丧的体验。我想知道为什么,因为这是我的应用程序需要的核心功能 Future initialize(context) async{ _firebaseMessaging.configure( onBackgroundMessage: Platform.isIOS ? null:_myBackgroundMessageHandle
onBackgroundmessage
未被触发,我在我的颤振应用程序上使用firebase消息
获得了一次令人沮丧的体验。我想知道为什么,因为这是我的应用程序需要的核心功能
Future initialize(context) async{
_firebaseMessaging.configure(
onBackgroundMessage: Platform.isIOS ? null:_myBackgroundMessageHandler,
);
}
Future<dynamic> _myBackgroundMessageHandler
(Map<String, dynamic> message) async {
print("onBackground Message called");
fetchRideInfoInBackground();
return Future<void>.value();
}
}
我看不到整个文件,但我假设您的
\u myBackgroundMessageHandler
不是顶级函数。将其设置为顶级或静态,之后它应该可以工作 编辑:示例
Future<dynamic> _myBackgroundMessageHandler (Map<String, dynamic> message) async {
print("onBackground Message called");
fetchRideInfoInBackground();
return Future<void>.value();
}
class PushHandler {
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
Future initialize(context) async{
_firebaseMessaging.configure(
onBackgroundMessage: Platform.isIOS ? null:_myBackgroundMessageHandler,
);
}
}
Future\u myBackgroundMessageHandler(映射消息)异步{
打印(“后台消息调用”);
fetchRideInfoInBackground();
返回Future.value();
}
类PushHandler{
最终FirebaseMessaging_FirebaseMessaging=FirebaseMessaging();
未来初始化(上下文)异步{
_firebaseMessaging.configure(
onBackgroundMessage:Platform.isIOS?null:\u myBackgroundMessageHandler,
);
}
}
您能添加一个示例吗?用示例编辑,示例无法正常工作,兄弟?我也做了顶级的。你想让我显示完整的代码吗。
Future<dynamic> _myBackgroundMessageHandler (Map<String, dynamic> message) async {
print("onBackground Message called");
fetchRideInfoInBackground();
return Future<void>.value();
}
class PushHandler {
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
Future initialize(context) async{
_firebaseMessaging.configure(
onBackgroundMessage: Platform.isIOS ? null:_myBackgroundMessageHandler,
);
}
}