我已经在iOS中构建了基于通知的应用程序我现在遇到的问题是,当屏幕上出现通知时,无法重定向到包含其数据的特定屏幕。我观察到的一件事是,如果我NSLog它,我得到该特定通知的所有值,但屏幕不会加载。在集成本地通知层次结构代码时,我是否遗漏了某些内容?
先谢谢你的帮助!!
以下是Appdelegate中的代码。
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
if([[notification.userInfo valueForKey:@"note"]isEqualToString:@"note"])
{
// nsuserdefault...
NSDateFormatter *dateFormatterN = [[NSDateFormatter alloc] init];
[dateFormatterN setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
NSString *currentTimeN = [dateFormatterN stringFromDate:notification.fireDate];
NSUserDefaults *prefnote=[NSUserDefaults standardUserDefaults];
[prefnote setObject:currentTimeN forKey:@"dateobject"];
[prefnote setObject:@"notification" forKey:@"notification"];
[prefnote synchronize];
NSBundle *bundle = [NSBundle mainBundle];
NSString *storyboardName = [bundle objectForInfoDictionaryKey:@"UIMainStoryboardFile"];
UIStoryboard *storyboardNote = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
UIViewController *vc1Note = [storyboardNote instantiateViewControllerWithIdentifier:@"Home"]; //if you assigned this ID is storyboard
UIViewController *vc2Note = [storyboardNote instantiateViewControllerWithIdentifier:@"AddNote"]; //if you assigned this ID is storyboard
NSArray *controllersNote = @[vc1Note,vc2Note];
UINavigationController *navControllerNote = (UINavigationController *)self.window.rootViewController;
[navControllerNote setViewControllers:controllersNote];
}
}
我使用了IF条件,因为我有3个类别并且基于特定类别它将被重定向到不同的屏幕。
答案 0 :(得分:0)
您已在此新导航控制器中创建了新的UINavigationController实例并设置了视图控制器。 但是你没有提供导航控制器。
你需要
或