前期準(zhǔn)備工作:
1.在極光推送后臺(tái)注冊(cè)應(yīng)用,生成appKey鹃祖;
2.創(chuàng)建推送證書府蔗,下載并雙擊保存在鑰匙串中刚陡,從鑰匙串的登錄-證書中找到生成的推送證書 導(dǎo)出.p12文件酝静;
3.在極光后臺(tái)為創(chuàng)建的應(yīng)用進(jìn)行推送配置薪丁,需要上傳推送證書产上。 好了假颇,到這里準(zhǔn)備工作就完成了!7绯印1钅俊!
①安裝
npm install jpush-react-native jcore-react-native --save (注:jpush-react-native自1.4.4后 需安裝jcore-react-native)
②link
react-native link (可指定庫(kù)進(jìn)行l(wèi)ink唁情, link過(guò)程需要輸入appKey)
注意:如果link失敗 即Xcode-Libraries中找不到 RCTJCoreModule.xcodeproj 和 RCTJPushModule.xcodeproj
③添加依賴庫(kù)
配置工程->選擇2:手動(dòng)導(dǎo)入
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甫匹,請(qǐng)不要添加)
UserNotifications.framework (Xcode8及以上)
libresolv.tbd (JPush 2.2.0及以上版本需要, Xcode7以下版本是libresolv.dylib)
libRCTJPushModule.a
libRCTJCoreModule.a
代碼實(shí)現(xiàn):注冊(cè)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];
}
啟動(dòng)極光推送SDK
[JPUSHService setupWithOption:launchOptions appKey:@"注冊(cè)得到的AppKey" channel:nil apsForProduction:false];
??????如果覺(jué)得對(duì)您有幫助甸鸟,麻煩請(qǐng)點(diǎn)個(gè)??哦