首先,官方文档,这是你必看的。虽然看了之后你也会报错...
然后记录下我的集成步骤:(按我的步骤来应该不会有错)
1. 插件安装(不要用npm install,不然你会遇到很多错误,会让你蛋疼得一逼)
yarn add jpush-react-native --save
yarn add
jcore-react-native --save
2.导入极光的库到xcode(检查下库是否导入xcode)
react-native link
3.自动配置(在xcode中自行添加代码,并且配置依赖库)
yarn run configureJPush d4ee2375846bc30fa51334f5(这是你的appkey,此处官方事例key) app(app名字,ios可不添)
4.进去看代码,官方给的代码对照下,在对应位置把你的appkey和相关配置配置好
[JPUSHService setupWithOption:launchOptions appKey:appKey //极光Key
channel:channel apsForProduction:false]; //false是开发环境,true表示发布环境
5.添加js代码
将下面代码放在第一个Component里面

if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
}
else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定义categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
}
else {
//categories 必须为nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
[JPUSHService setupWithOption:launchOptions appKey:@"极光ID"
channel:nil apsForProduction:false];