我有一個關於在應用程序內部顯示本地通知提醒的問題。我認爲問題在於視圖控制器。Tabbar環境中的通知提醒
這裏是我到目前爲止的代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[Number1ViewController alloc] initWithNibName:@"Number1ViewController_iPhone" bundle:nil];
viewController2 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPhone" bundle:nil];
} else {
viewController1 = [[Number1ViewController alloc] initWithNibName:@"Number1ViewController_iPad" bundle:nil];
viewController2 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
UILocalNotification *notification = [launchOptions objectForKey:
UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
NSString *stringReminder = [notification.userInfo
objectForKey:@"TextforReminder"];
[viewController showReminder:stringReminder];
}
}
application.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
或:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
application.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSString *stringReminder = [notification.userInfo
objectForKey:@"TextforReminder"];
[viewController showReminder:stringReminder];
}
}
關於視圖控制器但是我得到的錯誤。使用未聲明的標識符'viewController'。我明白,這是因爲沒有視圖控制器,但我並不是不知道該如何實現,而是在過程中顯示提醒。
非常感謝您的幫助,我沒有進一步解決這個問題。
乾杯
謝謝您的快速回復! /我已經完成了你所說的,但我仍然收到兩個錯誤:在第一部分中,我得到:實例消息的接收器類型'UIViewController'沒有聲明一個選擇器'showReminder:'的方法,第二部分是:沒有已知的實例方法選擇器'showReminder:'//我非常感謝你的幫助,我知道我是一個新手,但我試圖儘可能地學習,但有時它不可能沒有專業人員的幫助:)歡呼 –
還是我必須在相應的視圖控制器中自己創建showReminder:方法? –
Number1ViewController或SettingsViewController是否有一個'showReminder:'方法?既然他們是你的課程,你只能知道。你是否也在'didFinishLaunchingWithOptions:''''didReceiveLocalNotification:''中獲得了這些警告? – NJones