【发布时间】:2020-07-18 21:49:14
【问题描述】:
我正在使用 Firebase 推送通知,并且我想在触发 onBackgroundMessage 时执行我的一些代码。它实际上被触发了,因为我在控制台中打印,但我尝试使用几个插件但没有运气。每次出现类似(未处理的异常:MissingPluginException(未找到通道flutter_ringtone_player上的方法播放的实现))时,我都会收到错误消息。我相信这是因为在应用程序的后台状态中没有应用程序的上下文,但是这个功能有什么用,我实际上可以在其中做什么?
我想在 onBackgroundMessage 被触发时播放声音。
super.initState();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
FlutterRingtonePlayer.play(
android: AndroidSounds.notification,
ios: IosSounds.glass,
looping: true, // Android only - API >= 28
volume: 0.8, // Android only - API >= 28
asAlarm: true, // Android only - all APIs
);
print("background message executed");
return null;
}
【问题讨论】:
标签: firebase flutter firebase-cloud-messaging