firebase - Firebase FCM onLaunch 代码在单击通知时未运行功能
问题描述
我正在使用 FCM 传递通知,一旦单击,就会将用户带到应用程序上的特定页面。目前,onMessage 和 onResume 函数工作得很好,但在启动时却不行。
我包括
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
和
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
因为我也在使用颤振本地通知。
我已经尝试删除这些行,但它们没有任何区别。
解决方案
好的,所以我遇到的问题是,当启动代码触发时,我的应用程序在加载启动页面时正在加载其他数据和函数等。我必须做的是在发射时我将通知保存在一个变量中。然后我在splash init完成后执行了我想要的代码
onLaunch: (Map<String, dynamic> notification) async {
print("onLaunch: $notification");
///Saving the notification to use once the rest of the initialising and
///Loading is done
launchNotification = notification;
},
然后,一旦其他进程的加载和初始化完成,我就运行了这个函数
onLaunchFunction() async {
await Future.delayed(Duration(milliseconds: 100));
Map tempNotification = launchNotification;
if (launchNotification != null) {
launchNotification = null;
///The rest of the function
}
}
我添加了一个延迟的未来,以确保我的代码在初始化时运行。这可能不需要
推荐阅读
- angular - 如何根据 ngModel 值更改更新 mat-select 选择选中/未选中?
- javascript - 是否有任何字符串散列函数可以在 dart 和 typescript 上给出相同的结果?
- javascript - 如何绕过嵌套元素重新渲染卡片?
- elasticsearch - 如何按elasticsearch中深层对象内的元素排序?
- javascript - 循环 querySelectorAll
- python - 如何随时间更改变量的时区
- android - 是否可以确定应用程序是否已在屏幕上消失/出现?
- python - 熊猫 value_counts() + 重量
- python - python执行后如何运行sqlite命令
- java - 我正在尝试从 springboot 控制器下载一个 zip 文件,但我得到了奇怪的响应。请协助