我已经在flutter中配置了firebase云消息传递,通知在前台工作。但是当应用程序在后台或被杀死时,通知就无法正常工作。
以下步骤已完成:
- 生成了应用程序ID和推送密钥,在https://developer.apple.com/account/resources/certificates/上。
- 将info.plist添加到ios/Runner文件夹中。
- 开启了推送功能。
- 将APNS证书上传到Firebase控制台。
- 在AppDelegate.swift中添加了几行代码。
还尝试删除了下面这行代码,如Flutter Firebase Cloud Messaging - Notification when app in background所建议的,但仍然没有起作用。
if (@available(iOS 10.0, *)) { [UNUserNotificationCenter currentNotificationCenter].delegate = (id) self; }
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");
});
还交叉检查了所有下面的设置是否被勾选。