Ios 当应用程序转到后台时更改rootview控制器(ApplicationIdentinterBackground)

Ios 当应用程序转到后台时更改rootview控制器(ApplicationIdentinterBackground),ios,background-task,backgroundtaskidentifier,Ios,Background Task,Backgroundtaskidentifier,当用户真正进入后台时,我需要显示黑屏。(不是应用程序将重新激活) 因此,我在ApplicationIdentinterBackground中这样更改我的根视图控制器 //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

当用户真正进入后台时,我需要显示黑屏。(不是应用程序将重新激活)

因此,我在ApplicationIdentinterBackground中这样更改我的根视图控制器

//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;
});
问题是它不起作用。我想是因为时间不够。所以我研究了延长背景时间,但仍然不好。当用户完全进入后台时,我应该如何做才能显示黑屏(当用户切换应用程序到应用程序时,他们会将我的应用程序视为黑屏)


当应用程序进入后台时,尝试向窗口添加新视图,而不是更改窗口的根视图控制器,并根据需要删除/隐藏它。将视图的背景色设置为黑色。祝你好运。

你这样做是为了给用户增加隐私吗?当用户返回应用程序时,您是否要更改回原始视图控制器?是。我将改回原来的VC。这段代码是否在你的应用程序代理的
applicationidenterbackground
回调中?不要将其包装在
dispatch\u async
中。快照是在该方法返回后获取的,因此您这样做会导致vc更改在获取快照后发生。是。它位于应用程序标识背景内。我取出了dispatch\u async,但它不工作。我需要首先访问web服务,如果它返回yes,我将显示黑屏。添加覆盖屏幕的视图,而不是更改根视图控制器。然后在用户再次输入时将其删除。