以下代码是我在应用程序收到特定本地通知时显示视图控制器的最新尝试:
- (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,任何人都可以解释我做错了什么吗?我现在尝试了几种不同的方法,但我似乎无法让它发挥作用..
谢谢,
泰辛