iOS推送 (百度推送)

來源:互聯網
上載者:User

iOS推送 (百度推送)

最近在使用推送,所以與大家分享一下我所遇到的問題,與解決問題的方法!!

1.首先產生CertificateSigningRequest檔案。

點擊鑰匙串訪問-->從憑證授權單位請求認證-->填寫使用者郵件地址-->常用名-->點擊儲存-->繼續-->最後點擊儲存。

在案頭上就可以看見CertificateSigningRequest.certSigningRequest檔案就是CSR檔案,在我們產生CSR檔案的同時,會在鑰匙串訪問中產生一對秘鑰,名稱為剛才我們填寫的常用名。

 

 

2.開啟開發人員中心 首先建立Identifiers -->在建立Certificates -->在建立Provisoning Profiles

注意:1.建立Identifiers時,一定要勾選Push Notifications,

2.保證Identifiers中的ID,Certificates中的Name,Provisoning Profiles中的APP ID,應用程式中的Bundle identifier,保持一致。

 

3.點擊鑰匙串訪問-->我的認證-->找到剛剛產生的.p12檔案-->點擊匯出到案頭。

4.開啟中端 -->openssl pkcs12 -in push.p12 -out push.pem -nodes,將.p12檔案變成.pem檔案。

 

5.添加到SDK到?工程中的步驟如下:

將 libBPush.a 和 BPush.h 添加到?自?己的?工程下,添加時需要注意勾選當前Target

 

6.建立並配置BPushConfig.plist檔案,在工程中建立一個新的Property List檔案,並命名為BPushConfig.plist,添加以下索引值:

 

{    “PRODUCTION_MODE” = NO    “API_KEY” = “uZbmgZKhfumvGYGowcjSPFc1”     “DEBUG” = NO}

 

PRODUCTION_MODE:

必選。應用發布模式。開發認證簽名時,值設為”NO”;發布認證簽名時,值設為”YES”。請在調試和發布應用時,修改正確設定這個值,以免出現推播通知無法到達。

API_KEY:

必選。百度開發人員中心為每個app自動分配的api key,在開發人員中心app基本資料中可以查看。

 

6.SDK需要以下

庫: Foundation.framework 、 CoreTelephony.framework 、 libz.dylib 、 SystemConfiguration.framework ,請在?工程中添加

 

7.在 AppDelegate 中的 application: didFinishLaunchingWithOptions: 中調?用 API,初始化Push:

因為iOS8中對於推送有更改,所以要判斷裝置的版本

 

[BPush setupChannel:launchOptions];[BPush setDelegate:self]; //參數對象必須實現onMethod: response:方法,
#if SUPPORT_IOS8//    8.0以後使用這種方法來註冊推播通知    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {        UIUserNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];    }else#endif    {        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];    }

8. 在application: didRegisterForRemoteNotificationsWithDeviceToken:中調用API,註冊device token:

 

 

 [BPush registerDeviceToken:deviceToken]; // 必須     [BPush bindChannel]; // 必須。可以在其它時機調用,只有在該方法返回(通過onMethod:response:回調)綁定成功時,app才能接收到Push訊息。一個app綁定成功至少一次即可(如果access token變更請重新綁定)。

9. 實現BPushDelegate協議,必須實現方法onMethod:response::

 

 

 if ([BPushRequestMethod_Bind isEqualToString:method])     {        NSDictionary* res = [[NSDictionary alloc] initWithDictionary:data];        NSString *appid = [res valueForKey:BPushRequestAppIdKey];        NSString *userid = [res valueForKey:BPushRequestUserIdKey];        NSString *channelid = [res valueForKey:BPushRequestChannelIdKey];        int returnCode = [[res valueForKey:BPushRequestErrorCodeKey] intValue];        NSString *requestid = [res valueForKey:BPushRequestRequestIdKey];    }

 

10.在application: didReceiveRemoteNotification:中調用API,處理接收到的Push訊息:

擷取推送後返回的資料

 

[BPush handleNotification:userInfo]; // 可選

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.