gpt4 book ai didi

ios - 处理多个推送通知时出错

转载 作者:行者123 更新时间:2023-12-03 08:56:23 24 4
gpt4 key购买 nike

当屏幕打开时,我会通过自动推送到detailViewController来处理推送通知。当有一个或两个推送通知时,它可以正常工作,因为我可以将每个detailViewController彼此叠加,然后将其 pop 。但是,当我必须 pop 两个以上detailViewControllers时,应用程序崩溃。它仅在iOS 7+中发生。

最佳答案

设定通知编号

- (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和推送并 pop View 。
@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;
}
}

现在在您的类(class)中使用Bace类(class)
@interface detailViewController : CustomViewController

关于ios - 处理多个推送通知时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23951596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com