vin*_*thp 4 iphone alarm ios uilocalnotification
在我的应用程序中我正在使用闹钟功能.它工作正常.当我点击右键时,它会启动我的应用程序.但我想启动View Controller,它不是rootViewController.我尝试在Google和SO搜索,但我无法得到任何想法或例子.
我正在寻找任何一个例子来实现这一目标.
谢谢你的帮助.
编辑
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Add the view controller's view to the window and display.
[self.window addSubview:alarmViewController.view];
[self.window makeKeyAndVisible];
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(@"Recieved Notification %@",localNotif);
window = [[UIApplication sharedApplication] keyWindow];
UIViewController *rootViewController = [window rootViewController];
[rootViewController presentModalViewController:receipeViewController animated:YES];
}
// Override point for customization after application launch.
return YES;
Run Code Online (Sandbox Code Playgroud)
}
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running
NSLog(@"Recieved Notification %@",notif);
//Called here as well
window = [[UIApplication sharedApplication] keyWindow];
UIViewController *rootViewController = [window rootViewController];
[rootViewController presentModalViewController:receipeViewController animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
最后,我就是这样做的.
在didFinishLaunchingWithOptions中:
//save the root view controller
[[self window] makeKeyAndVisible];
UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;
rootController = [[navigationController viewControllers] objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
应用代理中的其他位置:
[rootController performSegueWithIdentifier:@"destinationSegue" sender:self];
Run Code Online (Sandbox Code Playgroud)
然后,在故事板中,从视图中创建一个segue,将其分配给"rootController"到所需的可选视图,并为新的segue提供id destinationSegue.需要一些调试才能确保将rootController变量分配给正确的视图.
| 归档时间: |
|
| 查看次数: |
5292 次 |
| 最近记录: |