在程序关闭时,收到推送消息是不会走 remove 哪个代理方法的,只会在程序启动的时候 走 didFinishLaunchingWithOptions这个方法(在app delegate.m里面),推送消息的相关信息会在launchOptions这个参数里面,可以写一个UIAlertView 弹出展示下,然后具体操作。
希望对你有帮助!
------------
最新版本的已经不需要单独操作了,友盟有两个回调方法,一个前台,一个后台(包括软件退出状态)。
//iOS10新增:处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//应用处于前台时的远程推送接受
//关闭U-Push自带的弹出框
[UMessage setAutoAlert:NO];
//必须加这句代码
[UMessage didReceiveRemoteNotification:userInfo];
}else{
//应用处于前台时的本地推送接受
}
//当应用处于前台时提示设置,需要哪个可以设置哪一个
completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
UIViewController * viewc = [ nav.viewControllers lastObject] ;
if (![viewc isKindOfClass:[LcNewsViewController class]]) {
UIAlertController * alec = [[LCHTTPRequest2 sharedHttpsRequest] lcAleShow:@"您有一条新消息!" andCancel:@"取消" OthersTitle:@"去查看", nil];
[LCHTTPRequest2 sharedHttpsRequest].tooldelegate = self;
[nav presentViewController:alec animated:YES completion:nil];
}
}
//iOS10新增:处理后台点击通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//应用处于后台时的远程推送接受
//必须加这句代码
[UMessage didReceiveRemoteNotification:userInfo];
LcNewsViewController * nnn = [[LcNewsViewController alloc]init];
[nav pushViewController:nnn animated:YES];
}else{
//应用处于后台时的本地推送接受
}
}