我正在使用 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 …Run Code Online (Sandbox Code Playgroud) 我遵循了 Socket.IO 管理 UI ( https://socket.io/docs/v4/admin-ui/ ) 的文档,这非常简单,但我无法让它工作。
让我告诉你,我的 socket.io 代码运行得很好。
我的代码:
const { instrument } = require("@socket.io/admin-ui");
instrument(io, {
auth: {
type: "basic",
username: "example",
password: "$2a$10$Jisp23q0LsLDWTxS3p5MzOxf4Lu9y6r.example"
}
});
Run Code Online (Sandbox Code Playgroud)
问题是,当我输入服务器 url并点击连接(没有用户名和密码)时,它实际上已连接,但没有数据流量。它总是为零。
为什么它忽略我的凭据以及为什么即使它说它已成功连接到 socket.io 服务器也没有流量?