Cannot snapshot view warning

Hello.


I'm running Xcode 8 and I'm working on a simple iOS app (version 9.3) and I'm getting the unusual warning message below under some circumstances:


2016-09-18 00:28:29.415 Home Inventory[8771:1832051] Cannot snapshot view (<UIKeyboardImpl: 0x7fee7b73c420; frame = (0 0; 320 253); layer = <CALayer: 0x60000022ae00>>) with afterScreenUpdates:NO, because the view is not in a window. Use afterScreenUpdates:YES.


I'm not calling snapshotView so I don't know why I'm getting this message. It only occurs when I click in a text field, the keyboard appears, and I then click outside the text field which causes the view containing the text field to call endEditing which removes the keyboard. I then press the Home button and that's when the warning above appears. I don't get the warning if the keyboard is still visible when I click the Home button. The app works fine even when the warning appears. I've been able to determine that the warning is triggered sometime after applicationDidEnterBackground has completed execution.


Is this a bug in Xcode or did I neglect to set some attribute somewhere?


Thanks in advance for any advice.


Bill

Post not yet marked as solved Up vote post of wbonetti Down vote post of wbonetti
24k views

Replies

A little more info for my original message. I'm using Swift 3 in Xcode 8 and saw this on both iPhone 5s and iPad Air simulators.


Thanks.

"I'm not calling snapshotView so I don't know why I'm getting this message." – if you aren't calling the method that causes this warning, then there isn't anything you can do aside from Reporting a Bug.

That was my thought as well, but I wondered if there was some setting I missed somewhere that might have caused this. It looks like the the system is doing the snapshot of all views because it pops right back when I return.


I'm new at this. How do I report a bug to Apple?


Thanks.

Report Bugs


Dirk

I am getting the same issue. I can confirm this issue exists.

I saw the same warning when shutting the app using the home button in the simulator and then re-activating it. My guess it is something that iOS is doing to display the app quickly on launch. Possibly using the UIView method drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES which was added in iOS 7 to let you render a snapshot of the complete view hierarchy (as visible onscreen) into a bitmap context.

Hi, this happened to me as well 😐 Did you get any response about that?

I have the same issue. If I run the app in instruments(leaks) it shows 2 X NSMutable Set leaks(No Ivar), appears to be when keyboard is dismissed.


Am trying to figure out if this is a problem or a one off leak associated with the Snapshot issue.


Does you app show the leaks?


Any ideas?

Hi guys, i realized that this warning only appears to me when you double tap the home button (multitask).


The system does a snapshot to show it to the user. (It seems like the app is running but it is an screenshot).


Anyway, i do not know if it is our problem / bug about render the view or something about iOS and xCode debugging.


Cheers.

The reason that this occurs is because the screen is snapshot every time that the app is exited. Why? Try double clicking the home button while in the app to see all open apps. Those views of the apps are not live views, but screenshots. Every time you close the app it will screenshot it so that it can show it here. I believe that it occurs during the AppDelegate's `applicationWillResignActive` or `applicationDidEnterBackground`.


There is nothing that you can do to prevent this, but some people choose to display a new view while the app is in the background to prevent private information from being included in this screenshot (think of a banking app).

Sometimes such warning might appear when you a trying to layout a UIView, which is not inside view hierarchy of the current window (for instance on device rotation). I faced this issue while working with UICollectionView. The solution, which helped me was to override "- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates" method of the UIView subclass, which throws this warning, as follows:


- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates {

BOOL au = afterUpdates;

if(!afterUpdates && self.window == nil) {

au = YES;

}

return [super snapshotViewAfterScreenUpdates:au];

}

No warnings any more.

Post not yet marked as solved Up vote reply of vgk Down vote reply of vgk

I had the same warning. Wrote this right after calling another view:


myview.view.snapshotView(afterScreenUpdates: true)