[英]Avoid loading main viewcontroller on receive of push notification ios
I am using this below code on receive of push notification to show my viewcontroller
. 我在接收推送通知时使用以下代码来显示我的viewcontroller
。 It is working fine but it first load the main viewcontroller
and then notification viewcontroller
. 它工作正常,但先加载主viewcontroller
,然后再加载viewcontroller
。 So every time user gets notification they see two viewcontrollers
loading first the main and then notification controller
. 因此,每次用户收到通知时,他们都会看到两个viewcontrollers
controller
首先加载主viewcontrollers
,然后再加载通知controller
。
How can i avoid this? 我如何避免这种情况? From UI perspective it does not look good to load two view controllers. 从UI角度来看,加载两个视图控制器看起来不太好。
UIViewController *main=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"main"];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:main];
self.window.rootViewController =nil;
UIViewController *destCon = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"RelNoti"];
UINavigationController *desNevCont = [[UINavigationController alloc] initWithRootViewController:destCon];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:desNevCont animated:YES completion:nil];
在这行中将动画设置为“否”,
[self.window.rootViewController presentViewController:desNevCont animated:NO completion:nil];
You can simply change the rootViewController of your app at the time of detecting push notification like below and avoid the transition between views: 您可以在检测到如下所示的推送通知时简单地更改应用程序的rootViewController,并避免视图之间的转换:
UIViewController *destCon = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"RelNoti"];
UINavigationController *desNevCont = [[UINavigationController alloc] initWithRootViewController:destCon];
self.window.rootViewController = desNevCont;
[self.window makeKeyAndVisible];
From your below code, it seems that you are assigning mainViewController
as your rootViewController
and then presenting the notificationViewController
above it, which is what is creating transition of two views. 从下面的代码中,您似乎正在将mainViewController
分配为rootViewController
,然后在其上方显示notificationViewController
,这就是创建两个视图的过渡。 So, simply limit your code with the above code. 因此,只需将您的代码限制为上述代码。
self.window.rootViewController = navigationController; // You are doing it here
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:desNevCont animated:YES completion:nil]; // presenting here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.