在这里我们可以选择大厂的推送,优先使用极光推送,下一篇将介绍如何使用阿里推送。
使用说明
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];
通知勾选