代码之家  ›  专栏  ›  技术社区  ›  Rajesh

如何在应用程序进入后台时得到通知?

ios
  •  0
  • Rajesh  · 技术社区  · 10 年前

    在进入后台之前,我需要保护我的应用程序不被截屏。我在中添加了一个黑色视图 applicationDidEnterBackground: 但当我在iOS7模拟器中检查后台应用程序时,它并没有显示黑色图像,而是显示应用程序本身,如图所示。我如何解决这个问题?如果我在应用程序后台运行之前得到通知,这个问题可能会得到解决。如有任何帮助,将不胜感激。 enter image description here

    2 回复  |  直到 10 年前
        1
  •  0
  •   Totumus Maximus    10 年前

    在整个应用程序中实现所需功能的最佳方法是让应用程序导航到完全黑色的UIViewController。这样,当您长按home按钮并查看后台应用程序时,您就看不到任何内容。

    这两个功能将发挥作用:

    - (void) applicationDidEnterBackground:(UIApplication *)application
    {
        //navigate to the black view controller
        BlackViewController *controller = [[BlackViewController alloc] init];
    
        [yourNavigationController pushViewController:viewController animated:yourAnimationSettings];
    
        [controller release];   
    }
    
    - (void) applicationWillEnterForeground:(UIApplication *)application
    {
        //pop the black view controller so the user won't be bothered with it
        if(/*Check if your BlackViewController is the top of your navigationController stack*/)
        {
             [yourNavigationController popViewControllerAnimated:yourAnimationSettings];
        }
    } 
    
        2
  •  0
  •   rounak    10 年前

    您将在AppDelegate的 applicationDidEnterBackground