React-Native 消息推送

在这里我们可以选择大厂的推送,优先使用极光推送,下一篇将介绍如何使用阿里推送。

使用说明

PS: 真没想到极光大厂出的官方文档也有问题,这里列出是最新版本修复可用版

创建新项目

react-native init rn_jpush

过程(省略)

This will walk you through creating a new React Native project in /Users/huanghuanlai/dounine/github/rn_push
Using yarn v1.9.4
Installing react-native...
yarn add v1.9.4
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...

安装jpush

cd rn_jpush
npm install jpush-react-native jcore-react-native --save

自动配置

react-native link
rnpm-install info Linking jcore-react-native ios dependency 
rnpm-install info Platform 'ios' module jcore-react-native has been successfully linked 
? Input the appKey for JPush 自己的AppKey
patching android/settings.gradle...
patching android/**/AndroidManifest.xml...
patching android/**/build.gradle...
patching ios/**/AppDelegate.m...
done!
rnpm-install info Linking jpush-react-native ios dependency 
rnpm-install info Platform 'ios' module jpush-react-native has been successfully linked 
rnpm-install info Platform 'android' module jpush-react-native is already linked

修改AppDelegate.m中的下面代码

[JPUSHService setupWithOption:launchOptions appKey:@"xxxxxxxxxxxxxxxxx"
                        channel:nil apsForProduction:nil];
# 修改为
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
  entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
  [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
  [JPUSHService setupWithOption:launchOptions appKey:@"xxxxxxxx"
                        channel:nil apsForProduction:false];

通知勾选

image.png

image.png

消息发送

image.png

image.png

项目

https://github.com/dounine/rn_jpush

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容