ios - 从React Native App内的AppDelegate.m访问/接收值

标签 ios react-native appdelegate

我在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/

相关文章:

ios - 应用程序在搜索(过滤)NSDictionary 时崩溃

ios - POST 请求后删除 CoreData 对象

css - 如何设置 React Native <CheckBox> 组件的样式?

javascript - 在 expo react-native 中将图像转换为 base64(仅在前端): PayloadTooLargeError: request entity too large

appdelegate - Swift 4,必须仅在主线程中使用警告

ios - 我可以提交带有自签名 SSL 证书的 iOS 应用程序吗?

ios - 什么用作 TableView subview 的委托(delegate)和数据源?

android - 在 React Native 中从 Web 服务填充 ListView

swift - 避免因启动画面或错误的 Controller 激活而丢失小部件发送的通知

ios - 在 AppDelegate 中模态呈现来自 UITabBarController 的 VC