Iphone 在UILocalNotification之后加载视图
我想在触摸屏上显示本地通知的警报视图,我的问题如下Iphone 在UILocalNotification之后加载视图,iphone,objective-c,xcode,uilocalnotification,uiapplicationdelegate,Iphone,Objective C,Xcode,Uilocalnotification,Uiapplicationdelegate,我想在触摸屏上显示本地通知的警报视图,我的问题如下 UILocalNotification *localNotificationObject = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotificationObject) { firstObject = [[FirstViewController alloc]initWithNibName:@"Fi
UILocalNotification *localNotificationObject = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotificationObject)
{
firstObject = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
NSLog(@"noti %@",[localNotificationObject.userInfo valueForKey:@"Key 1"]);
// firstObject.title = @"FirstView";
[self.window addSubview:firstObject.view];
}
else if(localNotificationObject)
{
SecondViewController *secondObject = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
NSLog(@"noti %@",[localNotificationObject.userInfo valueForKey:@"Key 2"]);
[self.window addSubview:secondObject.view];
//secondObject.title = @"Second View";
}
else if(localNotificationObject)
{
ThirdViewController *thirdObject = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
NSLog(@"noti %@",[localNotificationObject.userInfo valueForKey:@"Key 3"]);
[self.window addSubview:thirdObject.view];
// thirdObject.title = @"Third View";
}
else
{
firstObject = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:firstObject];
[self.window addSubview:navC.view];
}
它们是三个视图v1、v2、v3,我在这三个不同视图的按钮上触发了代码。下面给出了这三个视图的代码,不同视图的代码不同
notificationObject_ViewOne = [[UILocalNotification alloc]init];
notificationObject_ViewOne.fireDate = [NSDate dateWithTimeIntervalSinceNow:20];
notificationObject_ViewOne.timeZone = [NSTimeZone defaultTimeZone];
notificationObject_ViewOne.alertBody = @"You are notified";
notificationObject_ViewOne.alertAction = @"View 1";
notificationObject_ViewOne.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", nil];
notificationObject_ViewOne.userInfo = infoDict;
[[UIApplication sharedApplication]scheduleLocalNotification:notificationObject_ViewOne];
[notificationObject_ViewOne release];
SecondViewController *sec = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:sec animated:YES];
[sec release];
在第二个视图中触发通知的代码是
notificationObject_ViewTwo = [[UILocalNotification alloc]init];
notificationObject_ViewTwo.fireDate = [NSDate dateWithTimeIntervalSinceNow:35];
notificationObject_ViewTwo.timeZone = [NSTimeZone defaultTimeZone];
notificationObject_ViewTwo.alertBody = @"You are notified";
notificationObject_ViewTwo.alertAction = @"View 2";
notificationObject_ViewTwo.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 2", @"Key 2", nil];
notificationObject_ViewTwo.userInfo = infoDict;
[[UIApplication sharedApplication]scheduleLocalNotification:notificationObject_ViewTwo];
[notificationObject_ViewTwo release];
ThirdViewController *ThirdObj = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:ThirdObj animated:YES];
[ThirdObj release];
现在,在应用程序代理中,我使用下面给出的代码处理通知
UILocalNotification *localNotificationObject = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotificationObject)
{
firstObject = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
NSLog(@"noti %@",[localNotificationObject.userInfo valueForKey:@"Key 1"]);
// firstObject.title = @"FirstView";
[self.window addSubview:firstObject.view];
}
else if(localNotificationObject)
{
SecondViewController *secondObject = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
NSLog(@"noti %@",[localNotificationObject.userInfo valueForKey:@"Key 2"]);
[self.window addSubview:secondObject.view];
//secondObject.title = @"Second View";
}
else if(localNotificationObject)
{
ThirdViewController *thirdObject = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];
NSLog(@"noti %@",[localNotificationObject.userInfo valueForKey:@"Key 3"]);
[self.window addSubview:thirdObject.view];
// thirdObject.title = @"Third View";
}
else
{
firstObject = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:firstObject];
[self.window addSubview:navC.view];
}
上面的代码是在应用程序委托文件的applicationdidefinish启动方法中编写的
所以我想在这里做的是当通知1的警报框出现时v1应该加载,当通知2的警报出现时v2应该加载
但问题是v1的加载非常完美,但是当涉及到v2和v3时,它们的userInfo为null,默认情况下加载v1。我在处理本地通知的UIApplication委托方法中也做了同样的操作,但结果仍然相同
请为我提供一些指导或相同的链接
提前感谢您从不检查密钥的值,只需检查它是否存在。看看你的第一个if语句。幸好你用了其他的,否则你会把所有的都装进去