简体   繁体   English

在UILocalNotification之后加载视图

[英]Loading views after the UILocalNotification

I would like to display view on the touch of the alert of the local notification, my problem is given below 我想在触摸本地通知警报时显示视图,我的问题如下

Their are three views v1, v2,v3 and i have triggered code on the button of these three different views the code for that is given below and varies from different views 它们是三个视图v1,v2,v3和i,它们已在这三个不同视图的按钮上触发了代码,下面分别给出了相应的代码,这些视图因不同的视图而异

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];

The code to trigger notification in the second view is 在第二个视图中触发通知的代码是

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];

Now inside the app delegate i am handling the notification with the code given below 现在在应用程序委托内部,我使用下面给出的代码处理通知

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]; 
}

The above code is written in application did finish launch method of the app delegate file 上面的代码写在应用程序确实完成了应用程序委托文件的启动方法

So what i want to do here is when alert box for notification 1 comes v1 should load, when alert for notification 2 comes v2 should load. 所以我要在这里做的是通知1的警报框应加载v1,通知2的警报应加载v2。

but the thing is v1 is getting loaded perfectly but when it comes to v2 and v3 the userInfo for them is null and v1 is loaded by default. 但是问题是v1正在完美加载,但是当涉及v2和v3时,它们的userInfo为null,并且默认情况下已加载v1。 I did the same in the UIApplication delegate method for handling local notification but still the same results. 我在处理本地通知的UIApplication委托方法中做了相同的操作,但结果仍然相同。

Kindly provide me some guidance or links for the same. 请为我提供一些指导或链接。

Thanks in advance 提前致谢

You never check your key's value you just check to see if it's there. 您从不检查密钥的值,而只是检查密钥是否存在。 Look at your first if statement. 查看您的第一个if语句。 It's a good thing you used elses or you would have loaded all of them. 您使用其他方法是一件好事,否则您将全部装入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM