无法使LocalNotifications在React-Native中运行

时间:2021-04-12 18:57:14

I am building a small project with pure React Native framework and would love to implement a LocalNotfications function(no PushNotification involved).

我正在使用纯React Native框架构建一个小项目,并且希望实现LocalNotfications函数(不涉及PushNotification)。

I looked up in the official docs and it seems that PushNotificationIOS.requestPermissions() that I've putted in top level js doesn't show the prompt at all and there is no error in console either.

我在官方文档中查找,似乎我在*js中放置的PushNotificationIOS.requestPermissions()根本没有显示提示,并且控制台中也没有错误。

After careful investigations, I tried remote push component: [https://github.com/darylrowland/react-native-remote-push] The promtp is correclt rendered, however, PushNotification.presentLocalNotification still get completely ignored even when I hook it with an onPress action.

仔细调查之后,我尝试了远程推送组件:[https://github.com/darylrowland/react-native-remote-push] promtp是correclt呈现的,但是,PushNotification.presentLocalNotification仍然完全被忽略,即使我挂钩它一个onPress动作。

Am I doing something wrong? I am getting a bit frustrated as documentation on LocalNotifications is very few at this stage. Thanks for your help!

难道我做错了什么?由于LocalNotifications的文档在这个阶段很少,我感到有点沮丧。谢谢你的帮助!

1 个解决方案

#1


0  

I believe in the current version of React Native there are a few problems that are still not closed. There are ways around it by modifying parts of Objective-C - for example described here: https://github.com/facebook/react-native/pull/1979 (it mentions all the opened issues for Push Notification). You can try to apply the pull request to your copy of react-native to see if that solves your problem.

我相信当前版本的React Native有一些问题仍未解决。通过修改Objective-C的部分方法可以解决这个问题 - 例如:https://github.com/facebook/react-native/pull/1979(它提到了Push Notification的所有已打开问题)。您可以尝试将pull请求应用于您的react-native副本,看看是否能解决您的问题。

Also make sure you added the native Push Notification library not only the .js part. Push notification is one of few components in React that requires some extra native library integration. See https://facebook.github.io/react-native/docs/linking-libraries-ios.html

还要确保您添加了本机推送通知库,而不仅仅是.js部分。推送通知是React中需要一些额外的本机库集成的少数组件之一。请参阅https://facebook.github.io/react-native/docs/linking-libraries-ios.html

#1


0  

I believe in the current version of React Native there are a few problems that are still not closed. There are ways around it by modifying parts of Objective-C - for example described here: https://github.com/facebook/react-native/pull/1979 (it mentions all the opened issues for Push Notification). You can try to apply the pull request to your copy of react-native to see if that solves your problem.

我相信当前版本的React Native有一些问题仍未解决。通过修改Objective-C的部分方法可以解决这个问题 - 例如:https://github.com/facebook/react-native/pull/1979(它提到了Push Notification的所有已打开问题)。您可以尝试将pull请求应用于您的react-native副本,看看是否能解决您的问题。

Also make sure you added the native Push Notification library not only the .js part. Push notification is one of few components in React that requires some extra native library integration. See https://facebook.github.io/react-native/docs/linking-libraries-ios.html

还要确保您添加了本机推送通知库,而不仅仅是.js部分。推送通知是React中需要一些额外的本机库集成的少数组件之一。请参阅https://facebook.github.io/react-native/docs/linking-libraries-ios.html