我已将Firebase Cloud Messaging配置为带有flutter的通知正在前台运行。但在后台运行或应用被杀死时无法正常工作。
完成以下步骤。
https://developer.apple.com/account/resources/certificates/
还尝试按照Flutter Firebase Cloud Messaging - Notification when app in background上的建议删除以下行,但仍无法正常工作。
如果(@available(iOS 10.0,*)){
[UNUserNotificationCenter currentNotificationCenter] .delegate =(id)自我;
}
Flutter Doctor
[✓] Flutter (Channel beta, v1.12.13+hotfix.6, on Mac OS X 10.14.5 18F132, locale en-IN)
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/setup/#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
You may also want to add it to your PATH environment variable.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] Connected device (3 available)
我注意到的一件事是,在首次安装应用程序时,并没有要求我检查是否允许该应用程序发送推送通知。
我的代码在登录页面之后的页面上有以下几行。
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
并交叉检查是否已勾选所有以下设置。
最佳答案
我的解决方案如下,它的工作原理。
publspec.yaml
firebase_messaging:^ 6.0.9
从ios/runner/AppDelegate.m或ios/runner/AppDelegate.swift中删除以下行。
如果(@available(iOS 10.0,*)){
[UNUserNotificationCenter currentNotificationCenter] .delegate =(id)自我;
}
在Dart代码中使用临时== false,应弹出以在通知时进行确认。
myFirebaseMessagingService.requestNotificationPermissions(
const IosNotificationSettings(
声音:true,徽章:true,警报:true,临时:false));
在Xcode之后的Push通知以及后台Fetch和远程通知中。