//推送相关的设置
[BPush setupChannel:launchOptions];
// 必须。参数对象必须实现(void)onMethod:(NSString*)method response:(NSDictionary*)data 方法,本示例中为 self
[BPush setDelegate:self];
//推送的通知事件
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
if (launchOptions) {
//截取apns推送的消息
NSDictionary* pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
//[self setRemoteInfo:pushInfo];
//[[NSNotificationCenter defaultCenter] postNotificationName:kMessageDidChangeNofication object:nil];
//获取推送详情
NSString *pushInfoStr = [NSString stringWithFormat:@"%@",[pushInfo objectForKey:@"aps"]];
NSLog(@"aps : %@",pushInfoStr);
}
#pragma mark - PNS Push Service
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[application setApplicationIconBadgeNumber:0];
//[self setRemoteInfo:userInfo];
[BPush handleNotification:userInfo];
NSLog(@"RemoteInfo : %@",userInfo);
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
#warning BPush - 自定义一个方法提交设备信息
//[self registClientWithDeviceToken:deviceToken];
[BPush registerDeviceToken: deviceToken];
[BPush bindChannel];
}
- (void) onMethod:(NSString*)method response:(NSDictionary*)data {
#warning BPush - 接受后台推送的信息
NSDictionary* res = [[NSDictionary alloc] initWithDictionary:data];
if ([BPushRequestMethod_Bind isEqualToString:method]) {
// NSString *appid = [res valueForKey:BPushRequestAppIdKey];
NSString *userid = [res valueForKey:BPushRequestUserIdKey];
NSString *channelid = [res valueForKey:BPushRequestChannelIdKey];
//NSString *requestid = [res valueForKey:BPushRequestRequestIdKey];
int returnCode = [[res valueForKey:BPushRequestErrorCodeKey] intValue];
self.bduid = userid;
if (returnCode == BPushErrorCode_Success) {
[[XZDataStore sharedObject] saveBDUid:userid];
[[XZDataStore sharedObject] saveBDChannelId:channelid];
}
} else if ([BPushRequestMethod_Unbind isEqualToString:method]) {
int returnCode = [[res valueForKey:BPushRequestErrorCodeKey] intValue];
if (returnCode == BPushErrorCode_Success) {
[[XZDataStore sharedObject] saveBDUid:@""];
[[XZDataStore sharedObject] saveBDChannelId:@""];
}
}
}