gpt4 book ai didi

firebase - flutter :FlutterFcmService - 致命:找不到回调

转载 作者:行者123 更新时间:2023-12-04 12:02:31 27 4
gpt4 key购买 nike

我想在我的 flutter 应用程序上使用 fcm,所以在创建 firebase 控制台并在我的 gradle 中安装了一些依赖项之后,如下所示:
build.gradle:项目

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
}
build.gradle:应用程序
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
...
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
}
并创建一个 Java Application 类:
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}

@Override
public void registerWith(PluginRegistry registry) {
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
并在 list 中添加这个应用程序类和意图过滤器:
<application
android:name=".Application"
android:label="sian_mobile"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
...
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
并安装 firebase_messaging: ^7.0.0在公共(public)场合
我写了这个简单的 FirebaseMessaging 代码:
  FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
@override
void initState() {
super.initState();

_firebaseMessaging.configure(
onMessage: (message) async {
print("-------> $message");
},
onResume: (message) async {
print("-------> $message");
},
onLaunch: (message) async {},
);
}
当我运行应用程序并且应用程序在前台时,我将通知从控制台推送到应用程序。在 vscode 控制台中,我收到了以下错误:
Installing build/app/outputs/flutter-apk/app.apk...
E/FlutterFcmService(11005): Fatal: failed to find callback
Connecting to VM Service at ws://127.0.0.1:41113/PSCQfaDH4oA=/ws
D/EGL_emulation(11005): eglMakeCurrent: 0xe83ba420: ver 2 0 (tinfo 0xc80dd6e0)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->size()I (greylist, reflection, allowed)
W/.sian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->get(I)I (greylist, reflection, allowed)
W/.ian_mobil(11005): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (greylist, reflection, allowed)
I/flutter (11005): -------> {notification: {title: test title, body: Test notification text}, data: {}}

最佳答案

当应用程序在前台时,看起来仍然收到推送消息。该问题可能是由于应用程序在后台时没有推送消息的处理程序造成的。我建议通过这个 guide设置后台消息处理程序。

关于firebase - flutter :FlutterFcmService - 致命:找不到回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63487515/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com