研究了下極光推送,最惡心的部分莫過(guò)于一系列證書的配置,
1、注意下p12的導(dǎo)出,特別需要注意,
正確方式是這樣的

正確導(dǎo)出方式,直接導(dǎo)出
錯(cuò)誤方式是這樣的
錯(cuò)誤方式,打開后導(dǎo)出
2、xcode 的配置

3、導(dǎo)入極光推送sdk,同時(shí),添加依賴庫(kù)
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)
真機(jī)編譯,沒(méi)報(bào)錯(cuò),好的接下來(lái)開始敲代碼
4、在AppDelegate.m里面添加 JPUSHRegisterDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
//iOS10以上
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
} else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//iOS8以上可以添加自定義categories
[JPUSHService registerForRemoteNotificationTypes:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) categories:nil];
} else {
//iOS8以下categories 必須為nil
[JPUSHService registerForRemoteNotificationTypes:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert)categories:nil];
}
BOOL isProduction = NO;// NO為開發(fā)環(huán)境,YES為生產(chǎn)環(huán)境
//廣告標(biāo)識(shí)符
NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
//Required(2.1.5版本的SDK新增的注冊(cè)方法,改成可上報(bào)IDFA,如果沒(méi)有使用IDFA直接傳nil
[JPUSHService setupWithOption:launchOptions appKey:APP_KEY
channel:nil
apsForProduction:isProduction
advertisingIdentifier:advertisingId];
//此處設(shè)置當(dāng)點(diǎn)擊icon時(shí)候進(jìn)入app 銷毀icon badge
NSInteger bagValue = [UIApplication sharedApplication].applicationIconBadgeNumber;
NSLog(@"bagValue -- %ld", bagValue);
if (bagValue != 0) {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[JPUSHService setBadge:0];
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
}
return YES;
}
#pragma mark -- 注冊(cè) DeviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[JPUSHService registerDeviceToken:deviceToken];
}
#pragma mark -- JPUSHRegisterDelegate
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger options))completionHandler
{
// Required
NSDictionary * userInfo = notification.request.content.userInfo;
NSLog(@"userInfo -- %@", userInfo);
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]
]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(UNNotificationPresentationOptionAlert); // 需要執(zhí)這個(gè)方法,選擇是否提醒戶,有Badge、Sound、Alert三種類型可以選擇設(shè)置
}
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
{
// Required
NSDictionary * userInfo = response.notification.request.content.userInfo;
NSLog(@"00000userInfo -- %@", userInfo);
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(); // 系統(tǒng)要求執(zhí)行這個(gè)方法
}
#pragma mark -- iOS 7 遠(yuǎn)程請(qǐng)求
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
#pragma mark -- iOS 6 或者以下遠(yuǎn)程請(qǐng)求
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[JPUSHService handleRemoteNotification:userInfo];
}
接下來(lái),我們從極光后臺(tái),推送一條消息過(guò)來(lái),打印出來(lái)的userInfo
userInfo -- {
"_j_msgid" = 2929855611;
aps = {
alert = "775wode ";
badge = 1;
sound = default;
};
}
我們看到 badge = 1,同時(shí)受到的消息為 alert = "775wode"
好的,我們?cè)侔l(fā)送一條消息

有比較就有發(fā)現(xiàn)
badge 值一直為1,同時(shí),我們發(fā)送了倆條消息,但是icon角標(biāo)上面一直顯示為1這樣解決,我們直接在極光的后臺(tái)設(shè)置badge值為 +1這樣每次發(fā)送消息的時(shí)候,在之前的基礎(chǔ)上面加1,數(shù)量變正常

直接后臺(tái)設(shè)置咯
以上,就是集成極光推送發(fā)送遠(yuǎn)程通知的內(nèi)容,個(gè)人認(rèn)為,集成不難,難的是,集成之前各種證書的配置,生產(chǎn)環(huán)境,開發(fā)環(huán)境,各種煩躁,希望大家一起加油?。?!