react native上的notifee组建可发送local notification和remote push notification,可订阅各种Event。我使用的是local notification。另一个与之对应的是expo notification,也是很好的组建,但我的app未来想用bare类型,脱离expo,所以优先选择notifee。
官方文档:https://notifee.app , 官方文档非常清晰。
安装注意事项:
按照官方文档的做法在iOS上运行没问题,但是androidd在运行命令:npx react-native run-android
的时候报如下错误:
Could not determine the dependencies of task ':app:processDebugResources'. > Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'. > Could not find any matches for app.notifee:core:+ as no versions of app.notifee:core are available. Searched in the following locations: - https://oss.sonatype.org/content/repositories/snapshots/app/notifee/core/maven-metadata.xml - https://repo.maven.apache.org/maven2/app/notifee/core/maven-metadata.xml - file:/Users/peterfan/workspace/react_proj/CareYouHealth/node_modules/jsc-android/dist/app/notifee/core/maven-metadata.xml - https://dl.google.com/dl/android/maven2/app/notifee/core/maven-metadata.xml - https://www.jitpack.io/app/notifee/core/maven-metadata.xml - file:/Users/peterfan/workspace/react_proj/CareYouHealth/node_modules/react-native/android/app/notifee/core/maven-metadata.xml Required by: project :app > project :notifee_react-native
查了不少文档,后参考 后在工程项目的 android 目录下的build.gradle文件中allprojects节点下添加了新的maven url。
allprojects { // other items … repositories { // existing local repositories defined … // ADD THIS BLOCK maven { url "$rootDir/../node_modules/@notifee/react-native/android/libs" } } }
运行权限注意事项:
1. IOS下需要先执行:await notifee.requestPermission(); 否则notification不生效。
2. Android下也需要授权。参见:https://notifee.app/react-native/docs/triggers 中的 Android 12 Limitations 部分。但按照这篇关于权限的文章 https://blog.teamairship.com/creating-reminders-with-notifee ,是从Android 13开始的,我觉得还是按官方文档执行。
标签:maven,core,app,notifee,react,native From: https://www.cnblogs.com/saaspeter/p/18428190