The view added to applicationDidEnterBackground is not displayed until the application returns from the background

I add imageView to the main application window in applicationDidEnterBackground:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
        UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"splashimage.png"]];
        splash.frame = self.window.bounds;
        [self.window addSubview:splash];
}

I expect that when I put the application in the background by pressing the home button of the device, then viewing the task manager, double-clicking the home button, I will see how splashimage.png is displayed. But it seems that the screenshot that is taken when the application goes into the background does not include this overlay image. I thought it would be, since I added a View image without animation.

Why can this happen?

UPDATE: even if I hide my window in applicationDidEnterBackground, I still see a full window, not closed, in the task manager after the application is placed in the background. The window becomes hidden some time after the application returns from the background when I press the home button.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
        //this does not work either!
        self.window.hidden = YES;
}

UPDATE: I understand, by the way, that applicationDidEnterBackground has 5 seconds to complete. Now I am only testing this with

self.window.hidden = YES;

in applicationDidEnterBackground and nothing in applicationWillResignActive, and the window is still not hidden when the application goes into the background; only when he comes back to the fore. So this tells me that there must be something else, somewhere in my application, which prevents this from happening in applicationDidEnterBackground. By the way, if I moved

self.window.hidden = YES;

applicationWillResignActive, , . , , , applicationDidEnterBackground. .

UPDATE: BannerViewController (iAd). UITabBarController. , , UITabBarController.

: , UITabBarController, BannerViewController (iAd). , , ...

UPDATE: BannerViewController.m :

[self.view addSubview:bannerView]

:

- (void)viewDidLayoutSubviews
{
    CGRect contentFrame = self.view.bounds, bannerFrame = CGRectZero;
    ADBannerView *bannerView = [BannerViewManager sharedInstance].bannerView;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
    NSString *contentSizeIdentifier;
    // If configured to support iOS <6.0, then we need to set the currentContentSizeIdentifier in order to resize the banner properly.
    // This continues to work on iOS 6.0, so we won't need to do anything further to resize the banner.
    if (contentFrame.size.width < contentFrame.size.height) {
        contentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        contentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }
    bannerFrame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSizeIdentifier];
#else
    // If configured to support iOS >= 6.0 only, then we want to avoid currentContentSizeIdentifier as it is deprecated.
    // Fortunately all we need to do is ask the banner for a size that fits into the layout area we are using.
    // At this point in this method contentFrame=self.view.bounds, so we'll use that size for the layout.
    bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];
#endif

    if (bannerView.bannerLoaded) {
        contentFrame.size.height -= bannerFrame.size.height;
        bannerFrame.origin.y = contentFrame.size.height;
    } else {
        bannerFrame.origin.y = contentFrame.size.height;
    }
    _contentController.view.frame = contentFrame;
    // We only want to modify the banner view itself if this view controller is actually visible to the user.
    // This prevents us from modifying it while it is being displayed elsewhere.
    if (self.isViewLoaded && (self.view.window != nil)) {
        [self.view addSubview:bannerView];
        bannerView.frame = bannerFrame;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
        bannerView.currentContentSizeIdentifier = contentSizeIdentifier;
#endif
    }
}

, , - , , BannerViewController.

UPDATE: , (bannerVC - BannerViewController).

- (void)applicationWillResignActive:(UIApplication *)application {

    [bannerVC.view snapshotViewAfterScreenUpdates:YES];
}

UPDATE: , applicationDidEnterBackground. , , AdBannerView , . , , applicationWillResignActive - , , "" . , AdBannerView, applicationDidEnterBackground, .

UPDATE: :

  • iAdSuite
  • TabbedBanner.
  • AppDelegate:
  • . ( , , )
  • "" , .
  • "", .

applicationWillResignActive applicationDidEnterBackground , - . applicationDidEnterBackground applicationWillResignActive, . . , applicationDidEnterBackground.

- (void)applicationWillResignActive:(UIApplication *)application {

    //works - but undesirable
    //[self addDummyView];
    //[_tabBarController.view snapshotViewAfterScreenUpdates:YES];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {

    //does not work - needs to work to show dummyview only when application actually goes into the background
    [self addDummyView];
    [_tabBarController.view snapshotViewAfterScreenUpdates:YES];
}

- (void)addDummyView {

    UIView *topView = _tabBarController.view;
    UIView *colorView = [[UIView alloc] initWithFrame:topView.frame];
    [colorView setBackgroundColor:[UIColor blueColor]];
    [topView addSubview:colorView];
    [topView bringSubviewToFront:colorView];
}
+4
3

: , .

WillResignActive.

+1

. , applicationDidEnterBackground "". , .

, "" , , . , .

, , . , , , .

0

All Articles