gpt4 book ai didi

ios - [React Native][IOS] 如何通过通知打开应用程序时捕获事件

转载 作者:行者123 更新时间:2023-11-29 11:32:57 24 4
gpt4 key购买 nike

React Native 有一个 PushNotificationIOS 模块来获取通知数据并监听 notificaitonregister 等事件。我想在通过通知打开应用程序时捕获一个事件:PushNotificationIOS.addEventListener('notification_open', myhandler);。有办法吗?

最佳答案

你有两个选择。

1。使用 PushNotificationIOS

您可以在重要的地方调用 PushNotificationIOS.getInitialNotification();。例如,您可以在应用的 index.js 文件中调用此方法并决定要呈现的组件。来自 the docs :

This method returns a promise. If the app was launched by a push notification, this promise resolves to an object of type PushNotificationIOS. Otherwise, it resolves to null.

2。使用原生 iOS App Delegate

来自 the UIApplicationDelegate documentation :

For example, if your app was launched because of an incoming remote notification, you might want to reconfigure your user interface to display data related to that notification. For a list of possible reasons why your app might be launched, see Launch Options Keys.

如果您出于某种原因需要提前知道,您可以检查 native application(_:willFinishLaunchingWithOptions:)application(_:didFinishLaunchingWithOptions:) 方法。请注意,这些方法是在 React Native 初始化之前调用的。这是大多数 React Native 应用不需要的更高级的用例。

关于ios - [React Native][IOS] 如何通过通知打开应用程序时捕获事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51813103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com