0

我想显示视图中的本地通知的警报的触摸,我的问题是下面加载意见

鉴于其三种视图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]; 
} 

给予代码的通知上面的代码写在申请做应用程序的委托文件

所以我想在这里做的光洁度启动方法是当通知1的警报框到来时v1应该加载,当通知2的警报到来时v2应该加载。

但事情是v1获得完美加载,但是当涉及到v2和v3时,userInfo对于它们是null,v1默认加载。我在UIApplication委托方法中做了同样的处理本地通知,但结果仍然相同。

请为我提供一些相同的指导或链接。

在此先感谢

回答

0

您从不检查您的密钥的值,您只需检查它是否在那里。看看你的第一个陈述。这是你使用过的一个好东西,或者你会加载所有这些东西。