单击通知时,Firebase FCM onLaunch 代码未 运行 起作用
Firebase FCM onLaunch code not running functions when clicking on notification
我正在使用 FCM 发送通知,点击后会将用户带到应用程序的特定页面。目前,onMessage 和 onResume 函数工作得很好,但在启动时却不行。
我包括
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
和
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
因为我也在用flutter本地通知
我已经尝试删除这些行,但它们没有任何区别。
好的,所以我遇到的问题是,当启动代码触发时,我的应用程序正在加载其他数据和功能 e.t.c 在加载启动页面上。我要做的是在启动时将通知保存在一个变量中。然后我在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
}
}
我添加了一个 future delayed 只是为了确保我的代码在初始化时会 运行。这可能不需要
我正在使用 FCM 发送通知,点击后会将用户带到应用程序的特定页面。目前,onMessage 和 onResume 函数工作得很好,但在启动时却不行。
我包括
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
和
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
因为我也在用flutter本地通知
我已经尝试删除这些行,但它们没有任何区别。
好的,所以我遇到的问题是,当启动代码触发时,我的应用程序正在加载其他数据和功能 e.t.c 在加载启动页面上。我要做的是在启动时将通知保存在一个变量中。然后我在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
}
}
我添加了一个 future delayed 只是为了确保我的代码在初始化时会 运行。这可能不需要