我在AppDelegate.m文件中形成了一个值,我需要在我的React Native iOS应用程序中访问它。
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"My token: %@", deviceToken);
[RCTPushNotificationManager application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
我想要在我的应用程序中使用此
deviceToken
。如何访问这个?
最佳答案
您需要为register事件注册一个侦听器。最好的地方是根组件的componentDidMount方法。
PushNotificationIOS.addEventListener('register', this.onDeviceToken);
在onDeviceToken中,您将 token 作为唯一参数接收,并且可以处理和/或存储它。
在文档中查看有关通知事件的示例。工作原理完全相同。
https://facebook.github.io/react-native/docs/pushnotificationios.html#examples
关于ios - 从React Native App内的AppDelegate.m访问/接收值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35007195/