iOS整合極光推送

來源:互聯網
上載者:User

標籤:

iOS整合極光推送

一、配置APNs

蘋果APNs(英文全稱:Apple Push Notification Service)

1.配置開發認證


![Uploading apns_13_803165.png …]

2.配置生產認證

和配置開發認證的流程相同。

3.將配置好的認證匯出為 .p12 檔案

一、註冊極光推送帳號

可登入 極光推送官網 註冊帳號。

註冊成功後進入控制台

二、整合極光推送SDK

sdk地址

我使用的是JPush-iOS-SDK-2.1.0。下載的檔案裡有個pdf檔案iOS+SDK+Integration+Guide.pdf,介紹了整合極光推送的詳細代碼。

在工程檔案中,做如下設定:

![Uploading apns_18_876090.png …]

下面是我寫的代碼:

AppDelegate.m檔案

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    //設定appKey    [JPushConfig registerJPush:launchOptions];    return YES;}#pragma mark 修改通知處理函數-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {    //推送訊息攜帶 content-available: 1 是Background 啟動並執行必須參數,如果不攜帶此欄位則與iOS7 之前版本的普通推送一樣。    //清空角標    [JPUSHService resetBadge];    if (!userInfo) {        completionHandler(UIBackgroundFetchResultNoData);        return ;    }    completionHandler(UIBackgroundFetchResultNewData);    //根據伺服器設定的 userInfo 的格式,進行解析}// Required-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {    [JPUSHService registerDeviceToken:deviceToken];}// Required-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    [JPUSHService handleRemoteNotification:userInfo];    application.applicationIconBadgeNumber = 0;}- (void)application:(UIApplication *)applicationdidReceiveLocalNotification:(UILocalNotification *)notification {    [JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];}-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {}- (void)applicationDidBecomeActive:(UIApplication *)application {    [application setApplicationIconBadgeNumber:0];}

JPushConfig.m檔案

/** 註冊 JPush */+(void)registerJPush:(NSDictionary *)launchOptions {    // Required    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {        //可以添加自訂categories        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |                                                          UIUserNotificationTypeSound |                                                          UIUserNotificationTypeAlert)                                              categories:nil];    } else {        //categories 必須為nil        [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |                                                          UIUserNotificationTypeBadge |                                                          UIUserNotificationTypeBadge)                                              categories:nil];    }    NSString *appKey = @"極光推送產生的KEY";    NSString *channel = @"App Store";//發布渠道,可以隨便定義    BOOL isProduction = false;//這個要根據極光推送控制台裡設定的是開發環境還是生產環境    //Required    [JPUSHService setupWithOption:launchOptions                           appKey:appKey                          channel:channel                 apsForProduction:isProduction];}

收到通知訊息後,在AppDelegate.m跳轉到指定介面的方法:

    UIViewController *vc = [[UIViewController alloc] init];    [self.window.rootViewController presentViewController:vc animated:YES completion:nil];

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.