单击通知时Firebase FCM onLaunch代码未运行功能
我使用FCM发送通知,一旦单击,就会将用户带到应用程序上的特定页面。目前,onMessage和onResume功能工作得很好,但在启动时却不行 我包括单击通知时Firebase FCM onLaunch代码未运行功能,firebase,flutter,dart,google-cloud-firestore,firebase-cloud-messaging,Firebase,Flutter,Dart,Google Cloud Firestore,Firebase Cloud Messaging,我使用FCM发送通知,一旦单击,就会将用户带到应用程序上的特定页面。目前,onMessage和onResume功能工作得很好,但在启动时却不行 我包括 <key>FirebaseAppDelegateProxyEnabled</key> <false/> 因为我也在使用颤振本地通知 我已经尝试过删除这些行,但它们没有任何区别。好的,所以我遇到的问题是,当启动代码启动时,我的应用程序在加载启动页面时加载了其他数据和函数e.t.c。我要做的是,在发射时,我将通知
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
因为我也在使用颤振本地通知
我已经尝试过删除这些行,但它们没有任何区别。好的,所以我遇到的问题是,当启动代码启动时,我的应用程序在加载启动页面时加载了其他数据和函数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;
},
我添加了一个延迟的future,以确保我的代码在初始化时运行。这可能不需要您仍在使用这种方式吗?你有没有开发出另一种(更清洁的——如果我可以这么说的话)方法?@MohammedAl sadi我没有改变它,因为它只是起作用。也许有更好的方法我没有研究过。如果你找到了,请告诉我?感谢GILO的回复。我今天(在阅读了你的答案后)才发现了使用SchedulerBinding的能力。在完成呈现UI后,它会回调任何函数(请阅读更多相关内容,我仍然不擅长颤振)。下面是一个示例代码:SchedulerBinding.instance.addPostFrameCallback((\u)=>YourFunctionComesher());
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
}
}