極光推送集成步驟:
1.登錄IOS Dev Center創(chuàng)建推送證書

App id創(chuàng)建,使用Explicit App ID的方式創(chuàng)建并開啟Push Notification功能
注意這里必須使用指定具體Bundle ID的方式不要使用通配符

描述文件Provisioning Profiles中 App ID需要修改成之前創(chuàng)建開啟Push Notification的App ID.
2.下載配置和證書并從鑰匙串中將推送證書以.P12的格式導(dǎo)出
3.上傳證書,并將app的Bundle ID填寫上去

4.將描述文件導(dǎo)入xcode
5.xcode開啟Remote notifications

6.導(dǎo)入API開發(fā)包到應(yīng)用程序項目
將SDK包解壓,在Xcode中選擇“Add files to '你的項目名稱'”,將解壓后的lib子文件夾里的APService.h 和libPushSDK.a添加到工程目錄中
必要的框架
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
Security.framework
Xcode7需要的是libz.tbd;Xcode7以下版本是libz.dylib
Build Settings
設(shè)置 Search Paths 下的 User Header Search Paths 和 Library Search Paths,比如SDK文件夾(默認(rèn)為lib)與工程文件在同一級目錄下,則都設(shè)置為"$(SRCROOT)"即可
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// Required
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];
}
// Required
//如需兼容舊版本的方式,請依舊使用[JPUSHService setupWithOption:launchOptions]方式初始化和同時使用pushConfig.plist文件聲明appKey等配置內(nèi)容。
[JPUSHService setupWithOption:launchOptions appKey:appKey channel:channel apsForProduction:isProduction]; //一般使用上面的方法,這個是新版本推出的方法。
可以在這里設(shè)置
// [JPUSHService setAlias:@"123" callbackSelector:nil object:nil];//對某一個特地用戶手機推送的時候會用到。
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Required
[JPUSHService registerDeviceToken:deviceToken];//獲得APNS返回的設(shè)備標(biāo)識符deviceToken
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required,For systems with less than or equal to iOS6
[JPUSHService handleRemoteNotification:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// IOS 7 Support Required 在這里處理點擊通知欄的通知之后的一些列操作,執(zhí)行什么方法寫在這里,例如跳轉(zhuǎn)到某個特定的界面
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
// 應(yīng)用正處理前臺狀態(tài)下,不會收到推送消息,因此在此處需要額外處理一下
if (application.applicationState == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收到推送消息"
message:userInfo[@"aps"][@"alert"]
delegate:nil
cancelButtonTitle:@"取消"
otherButtonTitles:@"確定", nil];
[alert show];
}
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];//這個方法可以寫在任意你想寫的地方,數(shù)量代表桌面圖標(biāo)上面推送通知的條數(shù)。一般寫在程序啟動之后。
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
//Optional
NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}
注冊接收自定義消息的通知
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSLog(@"收到了自定義信息");
NSDictionary * userInfo = [notification userInfo];
NSString * content = [userInfo valueForKey:@"content"];
NSDictionary *extras = [userInfo valueForKey:@"extras"];
NSLog(@"extras = %@",extras);
NSLog(@"content = %@",content);
//建立本地通知,如果程序在后臺的時候也會收到推送通知一樣的消息。也可以判斷在程序在前臺的時候做一些特別的操作。
[JPUSHService setLocalNotification:[NSDate dateWithTimeIntervalSinceNow:10] alertBody:@"收到了自定義信息" badge:1 alertAction:@"adada" identifierKey:nil userInfo:nil soundName:nil];
}
7.監(jiān)聽通知
建議開發(fā)者加上API里面提供下面 5 種類型的通知:
extern NSString * const kJPFNetworkDidSetupNotification; // 建立連接
extern NSString * const kJPFNetworkDidCloseNotification; // 關(guān)閉連接
extern NSString * const kJPFNetworkDidRegisterNotification; // 注冊成功
extern NSString * const kJPFNetworkDidLoginNotification; // 登錄成功
溫馨提示:
Registration id 需要在執(zhí)行到kJPFNetworkDidLoginNotification的方法里獲取
extern NSString * const kJPFNetworkDidReceiveMessageNotification; // 收到自定義消息(非APNS)
其中,kJPFNetworkDidReceiveMessageNotification傳遞的數(shù)據(jù)可以通過NSNotification中的userInfo方法獲取,包括標(biāo)題、內(nèi)容、extras信息等
iOS SDK 集成指南
http://docs.jiguang.cn/guideline/ios_guide/#sdk