我在屏幕打开时通过自动推送到detailViewController来处理推送通知。当有一个或两个推送通知时,它可以正常工作,因为我可以将每个detailViewController推到彼此之上并将其弹回。但是,当我必须弹回两个以上的detailViewControllers时,应用程序崩溃。它仅在iOS 7 +中发生。
答案 0 :(得分:0)
设置通知ID
- (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]];
}
}
使用单例类作为基类并检查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