How to push a new view controller in didReceiveRemoteNotification so that the previous view controller does not appear for a moment?

I get an error notification and click on the view controller based on the data I receive. 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 manager, which was open before I pressed the home button, shows up for a moment.

I also tried this, but this happens the same thing:

 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 immediately and no other vc is shown for a moment?

+4
source share
4 answers

As you said, "but the view manager, which was open before I pressed the home button, shows up for a moment."

The reason is not in the code, but in the iOS system. It captures a screenshot of the screen when the application is running in the background. As documented :

Remove confidential information from submissions before moving on to the background . When the application goes to the background, the system takes a snapshot of the main application window, which it then presents briefly when the application goes to the foreground. Prior to returning from your application the DidEnterBackground: method, you must hide or hide passwords and other confidential personal information that may be captured as part of the snapshot.

So, if the snapshot is deleted, it will directly show the new pushed view controller. (not sure about Apple's snapshot guide)

Update:

One approach might be: Add a black background to the application screen when it goes in the background (in the applicationDidEnterBackground method). Thus, it will show a black screen, returning to the application. {They store it to display a startup image for an already running application.}

Where does this help?

When we delete snapshots from the Preferences directory of the applicationโ€™s sandbox (after the application is running in the background) and return to the application, it appears black for a while because it does not have a snapshot.

The result of our approach and the removal of the snapshot are the same.

+3
source

Since PictureTakeVC is a view controller, just use this instead

  PictureTakeVC *pvc = [[PictureTakeVC alloc] initWithNibName:@"PictureTakeVC" bundle:nil]; [self.navigationController pushViewController:pvc animated:YES]; 
+1
source

Before your application goes into the background, delete the displayed view.

+1
source

Are you missing something? didReceiveRemoteNotification launched when your application is active and running.

... but anyway, if you want to achieve what you are asking for, you need to find out that there is a pushnotification from didFinishLaunchingWithOptions (or maybe from applicationDidBecomeActive or applicationWillEnterForeground ) and click the viewcontroller on the rootviewcontroller from one of these methods.

To find out if there were deleted notifications:

 NSString *params = [[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"View"]; if (params) { // push view } 

Use the following methods to view, you will not see any other vc when the application is activated. Let me know if any problems arise.

 - (void)applicationWillEnterForeground:(UIApplication *)application { } - (void)applicationDidBecomeActive:(UIApplication *)application { } 

I did this for push notification, so let me know what you are trying to achieve if I misunderstood.

+1
source

All Articles