Ios 处理多个推送通知时出错
当屏幕打开时,我通过自动推送到detailViewController来处理推送通知。当有一个或两个推送通知时,它可以正常工作,因为我可以将每个detailViewController推到彼此的顶部,然后将其弹出。但是,当我必须弹出两个以上的DetailViewController时,应用程序会崩溃。它只在iOS 7+中发生。设置通知IdIos 处理多个推送通知时出错,ios,error-handling,push-notification,Ios,Error Handling,Push Notification,当屏幕打开时,我通过自动推送到detailViewController来处理推送通知。当有一个或两个推送通知时,它可以正常工作,因为我可以将每个detailViewController推到彼此的顶部,然后将其弹出。但是,当我必须弹出两个以上的DetailViewController时,应用程序会崩溃。它只在iOS 7+中发生。设置通知Id - (void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictio
- (void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if(app.applicationIconBadgeNumber!=0)
{
app.applicationIconBadgeNumber = app.applicationIconBadgeNumber - 1;
}
NSString *aps =[NSString stringWithFormat:@"%@",[userInfo objectForKey:@"id"]];
if (app.applicationState == UIApplicationStateActive)
{
NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]] forKeys:@[@"notifyText"]];
[arrNotificationData addObject:dict];
[self showNotificationInActiveMode:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];
}
if ([aps isEqualToString:@"1"])
{
[UserDefault setpushnotificationid:[aps intValue]];
}
if ([aps isEqualToString:@"2"])
{
[UserDefault setpushnotificationid:[aps intValue]];
}
if ([aps isEqualToString:@"3"])
{
[UserDefault setpushnotificationid:[aps intValue]];
}
if ([aps isEqualToString:@"4"])
{
[UserDefault setpushnotificationid:[aps intValue]];
}if ([aps isEqualToString:@"5"])
{
[UserDefault setpushnotificationid:[aps intValue]];
}
}
使用singleton类作为基类,检查ID和推送并弹出视图
@interface CustomViewController ()
@end
@implementation CustomViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(appBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
-(void)appBecomeActive
{
int val=[UserDefault getpushnotificationid];
if(val!=0){
[self checkforpushnotification];
}
}
-(void)checkforpushnotification
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
int val=[UserDefault getpushnotificationid];
[UserDefault setpushnotificationid:0];
//.: if current view is profile or setting just dismiss it.because they are present
switch (val)
{
case 1:
{
if( [self checkIfControllerExist:[DealsViewController class]])
{
return;
}else{
detailViewController *VC = (detailViewController *)[storyboard instantiateViewControllerWithIdentifier:@"VCView"];
[self.navigationController pushViewController:VC animated:YES];
}
}
break;
}
}
现在在课堂上使用bace类
@interface detailViewController : CustomViewController