我刚刚开始学习如何使用iOS和Parse实现推送通知。 目前,我可以从Parse仪表板向应用程序发送推送通知,收到通知,正如我在Xcode控制台中看到的那样,但现在我的问题是我无法从AppDelegate打开视图控制器。
这是我的代码:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
// Create empty photo object
NSString *photoId = [userInfo objectForKey:@"p"];
NSLog(@"P=%@",photoId);
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
Aceptado *targetViewController = (Aceptado*)[mainStoryboard instantiateViewControllerWithIdentifier:@"servicio_aceptado"];
UINavigationController *controlador = [[UINavigationController alloc]init];
[controlador pushViewController:targetViewController animated:YES];
}
正如我所说,控制台显示日志NSLog(@"P=%@",photoId)
,收到通知,但未显示视图控制器,显示任何警告或错误。
欢迎任何帮助。
答案 0 :(得分:5)
我已经解决了这个问题:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
bundle: nil];
Aceptado *controller = (Aceptado*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"servicio_aceptado"];
controller.id_not =_id_not;
controller.idemployee = _idemployee;
controller.fullname = _fullname;
controller.phone = _phone;
controller.photo = _photo;
controller.dni = _dni;
controller.licenseplate = _licenseplate;
controller.model = _model;
controller.color = _color;
controller.latitude = _latitude;
controller.longitude = _longitude;
self.window.rootViewController = controller;
现在我可以从AppDelegate文件向目标视图控制器传递值,保留SWRevealViewController结构。 感谢大家的提议。
答案 1 :(得分:0)
您不应该创建新的NavigationController,而是使用一个现有的。通常它是关键窗口的 rootViewController 属性。
试试这个:
UINavigationController *controlador = self.window.rootViewController;
如果要在SWRevealViewController中显示 targetViewController ,可以更改代码:
SWRevealViewController *controlador = (SWRevealViewController)self.window.rootViewController;
[controloador pushFrontViewController:targetViewController animated:YES];
如果您需要在SWRevealViewController上显示 targetViewController ,请使用:
WRevealViewController *controlador = (SWRevealViewController)self.window.rootViewController;
[controloador presentViewController:targetViewController
animated:YES
completion:nil];
如果您只需要用 targetViewController 替换SWRevealViewController,请使用:
self.window.rootviewController=targetViewController;
但请不要忘记将SWRevealViewController保存在其他属性中。
答案 2 :(得分:0)
试试这段代码。
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
Aceptado *targetViewController = (Aceptado*)[mainStoryboard instantiateViewControllerWithIdentifier:@"servicio_aceptado"];
UINavigationController *navVc=(UINavigationController *) self.window.rootViewController;
[navVc pushViewController: targetViewController animated:YES];
可以帮到你。
答案 3 :(得分:0)
尝试一次。
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
Slider1ViewController *viewcontroller = [storyBoard instantiateViewControllerWithIdentifier:@"Slider1ViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewcontroller];
[navController setViewControllers: @[viewcontroller] animated: YES];
[self.revealViewController setFrontViewController:navController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
答案 4 :(得分:0)
试试这个:
SomePageViewController *someVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SomeVC"];
self.navController = [[UINavigationController alloc] initWithRootViewController:someVC];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
答案 5 :(得分:0)
如果要将视图控制器从appDelegate推入导航堆栈,则需要将rootView控制器转换为UINavigation Controller