0

I need to show black screen when user really go to background. (Not applicationWillResignActive).

As a result, I am changing my root view controller like this in applicationDidEnterBackground.

//Before this, there will be Sync web-service call...normally, it is fast..time out is 2 second  
dispatch_async(dispatch_get_main_queue(), ^{
    UIViewController *vc = [[UIViewController alloc] init];
    [vc.view setBackgroundColor:[UIColor blackColor]];
    [AppDelegate instance].window.rootViewController = vc;
});

Problem is that it is not working. I thought it is because there is no enough time. So I study about extending background time and still not okay. How shall I do so that I will show black screen when user enter background totally (when user switch app to app, they will see my app as black screen)?

objective c - Proper use of beginBackgroundTaskWithExpirationHandler

Community
  • 1
  • 1
Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120
  • Are you doing this to add a level of privacy for the user? Are you going to change back to the original view controller when the users returns to the app? – DookieMan Mar 08 '16 at 16:20
  • Yes. I will change back to original VC. – Khant Thu Linn Mar 08 '16 at 16:22
  • Is that snippet in the `applicationDidEnterBackground` callback in your app delegate? Don't wrap it in a `dispatch_async`. The snapshot gets taken after that method returns so you are causing the vc change to take place after the snapshot is taken by doing that. – dan Mar 08 '16 at 16:24
  • yes. it is inside applicationDidEnterBackground. I take out dispatch_async and it is not working. I need to access web service first and if it return yes, I show black screen. – Khant Thu Linn Mar 08 '16 at 16:29
  • Add a view that covers the screen rather than changing the root view controller. Then remove it when the user enters again. – DookieMan Mar 08 '16 at 16:56

1 Answers1

0

Try adding new view to your window rather than changing window's root view controller when app enters background and remove/hide it as per your requirement. Set view's background color as black color. Good luck.

Maulik Bhuptani
  • 597
  • 3
  • 14