集成方法
1、在極光的官方網(wǎng)站中注冊(cè)應(yīng)用,獲取appKey,并且上傳APNS的開(kāi)發(fā)證書(shū)和生產(chǎn)證書(shū)
2、打開(kāi)工程的Push Notification 和 Background Modes(勾選Remote notifications)

打開(kāi)通知
3、在application didFinishLaunchingWithOptions里面配置
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
// 可以添加自定義categories
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
NSSet<UNNotificationCategory *> *categories;
entity.categories = categories;
}
else {
NSSet<UIUserNotificationCategory *> *categories;
entity.categories = categories;
}
[JPUSHService registerForRemoteNotificationTypes:entity.types categories:entity.categories];
}
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
if (resCode == 0) {//獲取registerID成功
NSLog(@"%@",registrationID);
}else{
//失敗
NSLog(@"%d",resCode);
}
}];
//apsForProduction:NO,開(kāi)發(fā)環(huán)境 ; YES,生產(chǎn)環(huán)境
[JPUSHService setupWithOption:launchOptions
appKey:JPushAppKey
channel:nil
apsForProduction:NO];
4、推送注冊(cè)
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/// Required - 注冊(cè) DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
}
5、實(shí)現(xiàn)JPUSHRegisterDelegate方法
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
// Required
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(UNNotificationPresentationOptionAlert); // 需要執(zhí)行這個(gè)方法,選擇是否提醒用戶(hù),有Badge、Sound、Alert三種類(lèi)型可以選擇設(shè)置
}
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
// Required
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(); // 系統(tǒng)要求執(zhí)行這個(gè)方法
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Required, iOS 7 Support
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required,For systems with less than or equal to iOS6
[JPUSHService handleRemoteNotification:userInfo];
}
- 注意:如果在確保證書(shū),配置都正確的情況下,發(fā)現(xiàn)不走注冊(cè)的方法,并且不走協(xié)議方法,并且,在工程里還用了環(huán)信的SDK,那么,原因一定出在環(huán)信重寫(xiě)了didRegisterForRemoteNotificationsWithDeviceToken 這個(gè)方法。簡(jiǎn)單的改正就是把JPush的注冊(cè)防盜環(huán)信重寫(xiě)的這個(gè)地方來(lái)。
// 環(huán)信重寫(xiě)的方法 將得到的deviceToken傳給SDK
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
[[EaseMob sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[JPUSHService registerDeviceToken:deviceToken];
}