避免在收到推送通知 ios 时加载 main viewcontroller
Avoid loading main viewcontroller on receive of push notification ios
我在接收推送通知时使用下面的代码来显示我的 viewcontroller
。它工作正常,但它首先加载主 viewcontroller
,然后加载通知 viewcontroller
。因此,每次用户收到通知时,他们都会看到两个 viewcontrollers
先加载主要内容,然后再加载通知 controller
。
我怎样才能避免这种情况?从 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];
在此行将动画设置为 NO,
[self.window.rootViewController presentViewController:desNevCont animated:NO completion:nil];
您可以像下面这样在检测到推送通知时简单地更改应用的 rootViewController 并避免视图之间的转换:
UIViewController *destCon = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"RelNoti"];
UINavigationController *desNevCont = [[UINavigationController alloc] initWithRootViewController:destCon];
self.window.rootViewController = desNevCont;
[self.window makeKeyAndVisible];
从您下面的代码来看,您似乎将 mainViewController
分配为 rootViewController
,然后在其上方显示 notificationViewController
,这就是创建两个视图的过渡。所以,简单地用上面的代码限制你的代码。
self.window.rootViewController = navigationController; // You are doing it here
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:desNevCont animated:YES completion:nil]; // presenting here
我在接收推送通知时使用下面的代码来显示我的 viewcontroller
。它工作正常,但它首先加载主 viewcontroller
,然后加载通知 viewcontroller
。因此,每次用户收到通知时,他们都会看到两个 viewcontrollers
先加载主要内容,然后再加载通知 controller
。
我怎样才能避免这种情况?从 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];
在此行将动画设置为 NO,
[self.window.rootViewController presentViewController:desNevCont animated:NO completion:nil];
您可以像下面这样在检测到推送通知时简单地更改应用的 rootViewController 并避免视图之间的转换:
UIViewController *destCon = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"RelNoti"];
UINavigationController *desNevCont = [[UINavigationController alloc] initWithRootViewController:destCon];
self.window.rootViewController = desNevCont;
[self.window makeKeyAndVisible];
从您下面的代码来看,您似乎将 mainViewController
分配为 rootViewController
,然后在其上方显示 notificationViewController
,这就是创建两个视图的过渡。所以,简单地用上面的代码限制你的代码。
self.window.rootViewController = navigationController; // You are doing it here
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:desNevCont animated:YES completion:nil]; // presenting here