标签:
在appdelegate中判断是否是从推送进入的app 如果是就把消息的内容用
NSNotification注册一个通知 然后去首页 接收这个通知判断消息内容 并且跳转到该页面 曾经难住的是在首页有一个跳转延时 导致的跳转不过去 如果不成功就加一个延迟让通知延迟0.5秒左右接收 时间看实际情况 恩就先这样吧 由于也得时间有点久了之前只是测试用来着后来功能干掉了 代码就删掉了
不知道是不是这个先贴出来再说
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { // NSLog(@"收到推送 %@",userInfo); [APService handleRemoteNotification:userInfo]; NSDateFormatter *DateFor = [[NSDateFormatter alloc] init]; DateFor.dateFormat = @"yyyyMMddHHmmssSSS"; NSDate *date = [NSDate date]; NSString *time = [DateFor stringFromDate:date]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (![userInfo[@"aps"][@"alert"] isEqualToString:@"线下支付成功"]) { [[Model manager] insertMessage:userInfo[@"aps"][@"alert"] anState:@"0" timeDate:time userid:[[NSUserDefaults standardUserDefaults] objectForKey:@"userid"]]; NSNotification *not1 =[NSNotification notificationWithName:@"xiaoxi" object:nil userInfo:userInfo]; [[NSNotificationCenter defaultCenter] postNotification:not1]; }else { [[Model manager] insertMessage:userInfo[@"aps"][@"alert"] anState:@"1" timeDate:time userid:[[NSUserDefaults standardUserDefaults] objectForKey:@"userid"]]; NSDictionary *dic = @{@"content":userInfo[@"aps"][@"alert"]}; NSNotification *not =[NSNotification notificationWithName:@"xianxia" object:nil userInfo:dic]; [[NSNotificationCenter defaultCenter] postNotification:not]; } }); NSArray *arr = [[Model manager] selectState:@"1" userid:[[NSUserDefaults standardUserDefaults] objectForKey:@"userid"]]; [[UIApplication sharedApplication] setApplicationIconBadgeNumber:arr.count]; completionHandler(UIBackgroundFetchResultNewData); }
标签:
原文地址:http://www.cnblogs.com/xiaoxiaolei/p/4969719.html