Reputation: 8035
I receive a pust notification and push a view controller based on the data i get in push. I do it like this:
UINavigationController *navVc=(UINavigationController *) self.window.rootViewController;
PictureTakeVC *pvc=[[PictureTakeVC alloc] init];
[navVc pushViewController:pvc animated:NO];
It works, but the view controller that was opened before i pressed home button shows for a moment.
I also tried this but it happens the same:
PictureTakeVC *pvc=[[PictureTakeVC alloc] init];
NSArray *vcs=[[NSArray alloc] initWithObjects: pvc, nil];
UINavigationController *navVc=(UINavigationController *) self.window.rootViewController;
navVc.viewControllers=vcs;
self.window.rootViewController = navVc;
How to push vc didReceiveRemoteNotification so that it opens immediatly and no other vc is shown for a moment?
Upvotes: 4
Views: 2562
Reputation: 8564
As you said "but the view controller that was opened before i pressed home button shows for a moment.",
The reason is not the code, but the iOS system. It captures screenshot of the screen when app goes in background. As documented:
Remove sensitive information from views before moving to the background. When an app transitions to the background, the system takes a snapshot of the app’s main window, which it then presents briefly when transitioning your app back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.
So, if snapshot is removed then it will directly show the new pushed view controller. (not sure about apple guideline for snapshot)
Update:
One approach can be:
Add a black colored background on the app screen when it goes in background(in applicationDidEnterBackground
method). So, it will show black screen while coming back to application.{ They store it for showing launch image for already started application.}
Where it helps?
When we delete snapshots from 'Preference' directory of application sandbox(after application goes in background) and come back to application it shows black for a while as it does not have any snapshot.
The outcome of our approach and removing snapshot are same.
Upvotes: 3
Reputation: 7504
Are you missing something? The didReceiveRemoteNotification
fires when your application is active and running.
...but anyway if you want to achieve what you are asking you have to detect there is a pushnotification from didFinishLaunchingWithOptions
(or may be from applicationDidBecomeActive
or applicationWillEnterForeground
) and push viewcontroller on rootviewcontroller from one of these methods.
To detect whether there were remote notification:
NSString *params = [[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"View"];
if (params)
{
// push view
}
Use following methods to push view, you won't see any other vc when application gets activated. Let me know if any issues.
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
I have done similar for push notification so let me know what are you trying to achieve exactly if I understood wrong.
Upvotes: 1
Reputation: 3805
Before your app goes into background mode remove the view that is there.
Upvotes: 1
Reputation: 1433
Since PictureTakeVC
is a view controller just use this instead
PictureTakeVC *pvc = [[PictureTakeVC alloc] initWithNibName:@"PictureTakeVC" bundle:nil];
[self.navigationController pushViewController:pvc animated:YES];
Upvotes: 1