前期准备工作:
1.在极光推送后台注册应用,生成appKey;
2.创建推送证书,下载并双击保存在钥匙串中,从钥匙串的登录-证书中找到生成的推送证书 导出.p12文件;
3.在极光后台为创建的应用进行推送配置,需要上传推送证书。 好了,到这里准备工作就完成了!!!!
①安装
npm install jpush-react-native jcore-react-native --save (注:jpush-react-native自1.4.4后 需安装jcore-react-native)
②link
react-native link (可指定库进行link, link过程需要输入appKey)
注意:如果link失败 即Xcode-Libraries中找不到 RCTJCoreModule.xcodeproj 和 RCTJPushModule.xcodeproj
③添加依赖库
配置工程->选择2:手动导入
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
Security.framework
libz.tbd (Xcode7以下版本是libz.dylib)
AdSupport.framework (获取IDFA需要;如果不使用IDFA,请不要添加)
UserNotifications.framework (Xcode8及以上)
libresolv.tbd (JPush 2.2.0及以上版本需要, Xcode7以下版本是libresolv.dylib)
libRCTJPushModule.a
libRCTJCoreModule.a
代码实现:注册APNS
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionSound|JPAuthorizationOptionBadge;
[JPUSHService registerForRemoteNotification Config:entity delegate:self];
#endif
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert) categories:nil];
}else {
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
}
启动极光推送SDK
[JPUSHService setupWithOption:launchOptions appKey:@"注册得到的AppKey" channel:nil apsForProduction:false];
😘😘😘如果觉得对您有帮助,麻烦请点个❤️哦