flutter - Flutter firebase消息:iOS手机没有消息捕获
问题描述
我正在尝试在我的应用程序上使用颤振 firebase 消息传递。我在pubspec.yaml文件中安装了这些库:
dependencies:
...
firebase_core: ^0.5.1
firebase_messaging: ^8.0.0-dev.9
在 android 中我没有任何问题但在 Ios 中,即使我的应用程序在前台,我也没有收到任何消息。事实上FirebaseMessaging.onMessage
并FirebaseMessaging.onBackgroundMessage
没有触发。
Future initialise() async {
//Firebase.initializeApp() I initialized on main method first
FirebaseMessaging _fcm = FirebaseMessaging.instance;
_fcm.requestPermission(alert: true, badge: true, sound: true);
if (Platform.isAndroid) {
_token = await _fcm.getToken();
print("------> token is: $_token");
} else if (Platform.isIOS) {
_token = await _fcm.getAPNSToken(); // token received from firebase
print("------> token is: $_token");
}
FirebaseMessaging.onMessage.listen((remoteMessage) async {
print('[onMessage] message: ${remoteMessage.data}');
var msg = PushMsgModel().wrapOriginMessage(remoteMessage);
_showOverlyNotify(msg);
});
FirebaseMessaging.onBackgroundMessage(onBackgroundMessage);
}
对于我添加的 IOS 配置
<key>FirebaseAppDelegateProxyEnabled</key> <false/>
在
Info.plist
.我创建了 APNs 证书并添加到 ios firebase 项目设置中
我注册了一个应用标识符
我生成了一个配置文件并添加到
Provisioning Profile
xcode 中。在 Xcode 中,我在 Project Navigator 中选择了 Runner。在里面
功能选项卡 我打开了推送通知和后台模式,并在后台模式下启用了后台获取和远程通知。
我还使用 Xcode 在 ios/Runner.xcworkspace 中复制了 GoogleService-Info.plist 文件。
AppDelegate.swift 包括:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
但是当我从firebase控制台推送消息时,我无法在android studio控制台上收到任何消息?我的错误是什么?有人能帮我吗?
当应用程序可以获取令牌意味着我的配置是正确的?
我正在使用软件版本 14.4在iPhone7plus(mobile)上进行测试
解决方案
我在真实设备上遇到了与 IOS 15.2 相同的问题,FirebaseMessaging.onBackgroundMessage
而我对 Android 没有任何问题。我花了几天时间测试不同的建议,三重检查我的配置,更新依赖项,测试自定义 APN 有效负载。没有任何效果。
对于我的情况,我意识到每次flutter run
在我的测试之间运行时,应用程序在调试模式下运行都会接受一个新的UUID
,因为会发生应用程序重新安装,因此,应用程序无法映射当应用程序具有新 UUID 时到达的通知并且从未触发后台处理程序。
当我在真实设备上以发布模式flutter run --release
对其进行测试时,确保UUID保持不变()最终我得到了预期的结果。iosDeviceInfo.identifierForVendor
推荐阅读
- r - 从数据框中的行复制与模式匹配的字符串并放入新数据框中的新列
- android - Koin 在关闭后重新注入实例
- sql - 需要通过查询验证日期跨度条件
- android - 在 InApp 计费库 [android] 的响应中检测测试购买
- python-3.x - 我的 ubuntu 服务器中的 Cron 作业无法启动
- puppet - kernel-devel 安装使用 puppet 抛出错误
- java - Whitelabel 错误页面 - 应用程序没有 /error 的显式映射
- gradle - Gradle复合构建`无法添加任务'包装器'作为具有该名称的任务已经存在。
- javascript - vue.js 元素 ui 将布尔数据绑定到选择列
- angularjs - Angular js中的当前路线