iOS推送 (百度推送)

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]; // 可選
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章