iOS 極光推送

來源:互聯網
上載者:User

標籤:

1.關於推送的幾個認證。http://www.mobile-open.com/2016/931624.html進入開發人員中心:https://developer.apple.com/account/ios/identifier/bundle, (1)建立 App ID,如果 ID 已經存在可以直接跳過此步驟。          為 App 開啟 Push Notification 功能。如果是已經建立的 App ID 也可以通過設定開啟 Push Notification 功能。

 

根據實際情況完善 App ID 資訊並提交,注意此處需要指定具體的 Bundle ID 不要使用萬用字元。  (2)建立認證需要注意選擇認證種類(開發認證用於開發和調試使用,生產認證用於 App Store 發布)

 

點擊 Continue 後選擇認證對應的應用ID,然後繼續會出現“About Creating a Certificate Signing Request (CSR)”。

 

根據它的說明建立開啟KeychainAccess 建立 Certificate Signing Request 

 

繼續返回Apple developer 網網站擊 Continue ,上傳剛剛產生的 .certSigningRequest 檔案產生 APNs Push Certificate。下載並雙擊開啟認證,認證開啟時會啟動“鑰匙串訪問”工具。

 

右擊剛剛產生的認證,匯出p12檔案(一共有2個P12檔案,匯出步驟一樣的)。注意: 匯出認證時要選中認證檔案,不要展開private key 

 

 (3)Provisioning Profile的建立          建立Provisioning Profile的前提,已在Apple Developer網站建立待發布應用所使用的Bundle ID的App ID,且為該App ID建立了APNs認證,如:在蘋果開發人員帳號的Provisioning Profile頁面點擊按鈕,建立Provisioning Profile

 

 

雙擊下載下來的Provisioning Profile,添加到xcode。到此為止,認證建立完成。 1.進入極光的官網,註冊,登入,並建立一個應用:https://www.jiguang.cn/

 

 

 

到這裡應用建立完成。   (4)設定項目:  (1)允許Xcode7支援Http傳輸方法如果您使用的是2.1.9以後的版本則不需要配置此步驟如果用的是Xcode7或更新版本,需要在App項目的plist手動設定下key和值以支援http傳輸。

全域配置

  <key>NSAppTransportSecurity</key> 
  <dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
  </dict
  (2)配置認證和開啟後台推送 

 開啟Remote notifications,需要在Xcode 中修改應用的 Capabilities 開啟Remote notifications

 

3.SDK整合步驟(參照官方文檔:http://docs.jiguang.cn/jpush/client/iOS/ios_guide_new/ )下面便是代碼部分

在Appdelegate.m中匯入標頭檔#import “JPUSHService.h”

在didFinishLaunchingWithOptions方法中寫入以下代碼,有的地方要按你自己的資訊填

 1 // Required 2 if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { 3     //可以添加自訂categories 4     [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |UIUserNotificationTypeSound |UIUserNotificationTypeAlert)categories:nil]; 5 } else { 6     //categories 必須為nil 7     [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)categories:nil]; 8 } 9 10 [JPUSHService setupWithOption:launchOptions appKey:你的appKey(字串),在極光的應用詳情中可以看到" channel:@""(這個不填就行) apsForProduction:這個值生產環境為YES,開發環境為NO(BOOL值)];11 12  13 14 建立15 16 -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken17 18 19 方法中註冊裝置(去掉這個)20 21 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {22     //這個方法是設定別名和tag 可省23     // [JPUSHService setTags:nil alias:@"WzxJiang" fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {24     //        NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, iTags , iAlias);25     //   }];26     // Required27     [JPUSHService registerDeviceToken:deviceToken];28 }29 30  31 32 建立33 34 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler:35 36 37 App在後台時收到推送時的處理38 39 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {40     //iOS 7及之後才能用,現在沒人適配iOS6了吧...41     // IOS 7 Support Required 42     [JPUSHService handleRemoteNotification:userInfo];43     completionHandler(UIBackgroundFetchResultNewData);44 }45 46  47 48 在applicationWillEnterForeground方法(App即將進入前台)中將小紅點清除49 50 - (void)applicationWillEnterForeground:(UIApplication *)application {51     NSLog(@"進入前台");52     [UIApplication sharedApplication].applicationIconBadgeNumber = 0;53 }54 56 57 建立58 59 didFailToRegisterForRemoteNotificationsWithError60 61 62 方法,處理接收推送錯誤的情況(一般不會…)63 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {64     //Optional65     NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);66 }
4.測試推送結果:  

 

 注意要在真機上運行,如果能夠收到自己推送的訊息,極光的整合就算完成了。 1.問題: 解決:雙擊認證:

 

 

 

  

 

2.應用在前台的時候是收不到訊息,也沒有小紅點提示的,應用在後台或者殺死的情況下是可以正常接收到訊息的。據說在iOS 10之後是沒有這個問題了,不過目前由於項目問題還沒有進行ios10的適配,希望能夠解決這個問題吧,對於整合極光推送有問題的小夥伴可以提出來一起討論,共同進步。

iOS 極光推送

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.