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!

相關問題