最近在使用推送,所以與大家分享一下我所遇到的問題,與解決問題的方法!!
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:
API_KEY:
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];
}
[BPush registerDeviceToken:deviceToken]; // 必須
[BPush bindChannel]; // 必須。可以在其它時機調用,只有在該方法返回(通過onMethod:response:回調)綁定成功時,app才能接收到Push消息。一個app綁定成功至少一次即可(如果access token變更請重新綁定)。
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]; // 可選