タブバーアプリケーションがあり、アプリケーションが実行されていない場合でも、2番目のタブに切り替えて、12:00にアラートをポップアップするとします。
UILocalNotificationのすべてのコードが正しく機能するようになりましたが、そのための最善の方法は、アプリの代理人からの通知を投稿することだと思いました。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
// Handle launching from a notification when the app is NOT running
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
[tabBarController setSelectedIndex:1];
[[NSNotificationCenter defaultCenter] postNotificationName:@"AlertNotification" object:self];
}
return YES;
}
次に、SecondViewController.mに次のようになります。
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popUpAlert:) name:@"AlertNotification" object:nil];
}
しかし、これは機能しません。SecondViewControllerのviewDidLoadがまだ呼び出されていないときに通知が送信されたのではないでしょうか?これを解決することは可能ですか?NSNotificationCenter
そして、この場合の私の使用方法に同意しますか?
前もって感謝します。