0

接收的本地通知下面的代码是显示一个视图控制器我的最新尝试时我的应用程序接收到特定本地通知:问题显示视图控制器当在iPhone上

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{ 
    NSLog(@"Notification Received. UserInfo: %@", [notification.userInfo valueForKey:@"notificationType"]); 
    if ([[notification.userInfo valueForKey:@"notificationType"] isEqualToString:@"backup"]) 
    { 
     NSLog(@"Backup notification received."); 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
     [defaults setObject:@"Yes" forKey:@"shouldBackup"]; 
     [defaults synchronize]; 
     SettingsViewController *vc = [self.window.rootViewController.tabBarController.viewControllers objectAtIndex:3]; 
     [self.window.rootViewController.tabBarController.navigationController pushViewController:vc animated:NO]; 
    } 
    else 
    { 
     NSLog(@"Did receive notification: %@, set for date:%@ .", notification.alertBody, notification.fireDate); 
    } 
} 

我然后有这一段代码,我在viewDidAppear方法用来确定羯羊或不执行备份:

if ([[defaults objectForKey:@"shouldBackup"] isEqualToString:@"Yes"]){ 
     [defaults setObject:@"No" forKey:@"shouldBackup"]; 
     [defaults synchronize]; 

     HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; 
     [self.navigationController.view addSubview:HUD]; 

     HUD.delegate = self; 
     HUD.labelText = @"Backing Up Your Data.."; 
     HUD.minSize = CGSizeMake(135.f, 135.f); 

     [HUD showWhileExecuting:@selector(performBackup) onTarget:self withObject:nil animated:YES]; 
    } 

然而,似乎viewDidAppear是从来没有所谓的,任何人都可以解释它是什么,我做错了什么?我现在已经尝试了几种不同的方法,我只是似乎无法得到它的工作..

感谢,

Tysin

回答

1

您需要的SettingsViewController压入栈从NavigationController在命令调用其委托方法(在本例中为viewDidAppear)。看来你的根视图控制器是一个TabBarController。在这种情况下,UINavigationControllerDelegate添加到您的根VC,更多信息关于下一步该怎么做可以在这里也可以找到http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca

,你确定viewDidAppear是没有得到所谓的或只是其中的代码是没有得到叫什么名字?找出一个断点。

最后,你有[super viewDidAppear:animated];在SettingsViewController的viewDidAppear方法中?

如果一切都失败了,你可以手动从父视图控制器:)

希望这有助于随时调用viewDidAppear!

相关问题