激光推送
第一步:先在開發者賬號創建app id,即創建應用程序ID
2、從開發者賬戶頁面左側入口進入“Certificates, IDs & Profiles” 頁面。?
3、創建 App ID,填寫 App ID 的 Name 和 Bundle ID(? ?注: 此處需要指定具體的 Bundle ID 不要使用通配符)。?
4、為 App 開啟 Push Notification 功能。如果是已經創建的 App ID 也可以通過設置開啟 Push Notification 功能。?
? 5、填寫好以上屬性后,點擊 “Continue”,確認 AppId 屬性的正確性,點擊 “Register”,注冊 AppId 成功。
第二步 配置證書,包括開發證書和生產證書兩個證書
簡述極光推送證書的基本生成流程,兩者都為導出的p12文件
?
開發證書的詳細步驟:
1、開發證書的生成(注意選擇的Development)。?
2、點擊continue,來到選擇App ID界面。?
3、說明讓上傳自己的CSR文件,continue...?
4、上傳請求生成的CSR文件,continue...?
5、打開系統自帶的 “鑰匙串訪問” 創建 Certificate Signing Request。如下圖操作:?
6、填寫“用戶郵箱”和“常用名稱” ,并選擇“存儲到磁盤”,證書文件后綴為.certSigningRequest 。
?
7、回到瀏覽器中 CSR 上傳頁面,上傳剛剛生成的后綴為 .certSigningRequest 的文件。?
8、生成證書成功后,點擊 “Download” 按鈕把證書下載下來,是后綴為 .cer 的文件(第一個為“Download”得到的生產開發證書,第二個為“Download”得到的開發證書)。??
9、雙擊證書后,會在“KeychainAccess”中打開,選擇左側“鑰匙串”列表中“登錄”,以及“種類”列表中“我的證書”,找到剛才下載的證書,并導出為 .p12 文件。如下圖:?
?
生產證書的詳細步驟:
1、注意這里的選擇方式和開發證書有略微的區別,選擇Production那一項就好?
2、以下的步驟略去,和開發的一樣,到最后下載一下文件,得到下面圖的兩個文件,雙擊在鑰匙串訪問中可見。
?
最后得到導出的證書(第二個)?
第三步?把導出的開發證書和生產證書分別上傳到極光平臺
1、在極光控制臺上,進入你應用的應用設置中 iOS 的鑒權方式選擇 “證書”,上傳剛才導出的 .p12 證書。極光會在后臺為你的應用進行鑒權。
第四步 集成極光推送SDK,配置工程
1、導入SDK
選擇1:Cocoapods導入
通過Cocoapods下載地址:
pod 'JPush'
如果需要安裝指定版本則使用以下方式(以3.0.2版本為例):
pod 'JPush', '3.0.2'
選擇2:手動導入
- 在極光官網下載最新 SDK?
- 將 SDK 包解壓,在 Xcode 中選擇 “Add files to 'Your project name'...”,將解壓后的 lib 子文件夾(包含 JPUSHService.h、jpush-ios-x.x.x.a、jcore-ios-x.x.x.a )添加到你的工程目錄中。
- 添加 Framework
- CFNetwork.framework
- CoreFoundation.framework
- CoreTelephony.framework
- SystemConfiguration.framework
- CoreGraphics.framework
- Foundation.framework
- UIKit.framework
- Security.framework
- libz.tbd(Xcode 7 以下版本是 libz.dylib)
- AdSupport.framework(獲取 IDFA 需要;如果不使用 IDFA,請不要添加)
- UserNotifications.framework(Xcode 8 及以上)
- libresolv.tbd(JPush 2.2.0 及以上版本需要,Xcode 7 以下版本是 libresolv.dylib)
注意: 如果集成 JPush 3.0.1 及以上版本, 且同時集成極光其他 SDK(如:JMessage 3.0.0 及以上版本)?
1. Cocoapods 導入,建議都更新為線上最新版本,來避免 JCore 版本不一致導致的沖突。?
2. 手動導入,在工程中只需保留一個最新版本的 jcore-ios-x.x.x.a 靜態庫文件。
Build Settings
如果你的工程需要支持小于 7.0 的 iOS 系統,請到 Build Settings 關閉 bitCode 選項,否則將無法正常編譯通過。
- 設置 Search Paths 下的 User Header Search Paths 和 Library Search Paths,比如 SDK 文件夾(默認為 lib )與工程文件在同一級目錄下,則都設置為 "$(SRCROOT)/{靜態庫所在文件夾名稱}" 即可。
Capabilities
如使用 Xcode 8 及以上環境開發,請開啟 Application Target 的 Capabilities->Push Notifications 選項,如圖:?
允許 Xcode 7 支持 Http 傳輸方法
如果您使用的是 2.1.9 及以上的版本則不需要配置此步驟??
如果用的是 Xcode 7 或更新版本,需要在 App 項目的 plist 手動配置下 key 和值以支持 http 傳輸:
選擇1:根據域名配置
- 在項目的 info.plist 中添加一個 Key:NSAppTransportSecurity,類型為字典類型。
- 然后給它添加一個 NSExceptionDomains,類型為字典類型;
- 把需要的支持的域添加給 NSExceptionDomains。其中 jpush.cn 作為 Key,類型為字典類型。
- 每個域下面需要設置 2 個屬性:NSIncludesSubdomains、NSExceptionAllowsInsecureHTTPLoads。 兩個屬性均為 Boolean 類型,值分別為 YES、YES。
如圖:
第五步 工程代碼部分
為 AppDelegate 添加 Delegate。
參考代碼:
@interface AppDelegate ()<JPUSHRegisterDelegate>@end?
在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中添加
// 1.注冊系統通知if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]){UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];[application registerUserNotificationSettings:settings];}// 2.注冊極光推送if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {//可以添加自定義categories[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)categories:nil];}[JPUSHService setupWithOption:launchOptions appKey:JPushAPPkeychannel:@"Publish channel"apsForProduction:NOadvertisingIdentifier:nil];// 接收應用內消息NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];// 極光推送登錄成功后可以注冊別名[defaultCenter addObserver:self selector:@selector(registerAlias:) name:kJPFNetworkDidLoginNotification object:nil];?
// 3.注冊 DeviceToken - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {[JPUSHService registerDeviceToken:deviceToken]; }#pragma mark - JPUSHRegisterDelegate // iOS 10 Support,前臺收到通知,后臺不會執行這個方法 - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {// RequiredNSDictionary * userInfo = notification.request.content.userInfo;if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}completionHandler(UNNotificationPresentationOptionAlert); // 需要執行這個方法,選擇是否提醒用戶,有Badge、Sound、Alert三種類型可以選擇設置// 通知內容為:notification.request.content.body}// iOS 10 Support,用戶點擊了通知進入app - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {// RequiredNSDictionary * userInfo = response.notification.request.content.userInfo;if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {[JPUSHService handleRemoteNotification:userInfo];}//處理推送邏輯completionHandler(); // 系統要求執行這個方法[UIApplication sharedApplication].applicationIconBadgeNumber = 0; }#pragma mark 綁定tag - (void)registerAlias:(NSNotification *)notification{// 注冊別名 // [JPUSHService setAlias:[NSString stringWithFormat:@"%@",[RYSave account].user_id] callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];[JPUSHService setAlias:[NSString stringWithFormat:@"%@",[RYSave account].user_id] completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {DLog(@"極光別名注冊的回調方法rescode: %ld, \n, \n alias: %@\n", (long)iResCode , iAlias);if (iResCode == 0) {// 注冊成功}} seq:1]; }// 極光別名注冊的回調方法 -(void)tagsAliasCallback:(int)iResCodetags:(NSSet*)tagsalias:(NSString*)alias {DLog(@"極光別名注冊的回調方法rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, tags , alias);if (iResCode == 0) {// 注冊成功} }#pragma mark 解析極光推送的應用內消息 - (void)networkDidReceiveMessage:(NSNotification *)notification {NSDictionary * userInfo = [notification userInfo];DLog(@"解析極光推送的應用內消息:%@",userInfo); }// 接收到遠程通知之后 - (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[JPUSHService handleRemoteNotification:userInfo];completionHandler(UIBackgroundFetchResultNewData); } //獲取 deviceToken 失敗后 遠程推送(極光推送)打開失敗 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {//OptionalDLog(@"獲取 device token 失敗 %@", error); }?綁定別名需要注意的是:在刪除綁定的時候把用戶唯一標示改為空
[JPUSHService setAlias:[NSString stringWithFormat:@"%@",<#用戶唯一標示#> completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {DLog(@"極光別名注冊的回調方法rescode: %ld, \n, \n alias: %@\n", (long)iResCode , iAlias);if (iResCode == 0) {// 注冊成功}} seq:1];?
轉載于:https://www.cnblogs.com/banwenzheng/p/10007628.html
總結
- 上一篇: PHP 使用程序进行数据库字典文件生成
- 下一篇: vuex入门文档