EmergeTools / SnapshotPreviews-iOS

📸 Automatic snapshots from Xcode previews. Supports UIKit/AppKit/SwiftUI on iOS/macOS/watchOS/visionOS/tvOS. Browse previews in-app with the Preview Gallery, or save them to PNGs with an XCTest
https://www.emergetools.com
MIT License
211 stars 7 forks source link

interface orientation errors on all local snapshot tests #161

Open jrames opened 3 weeks ago

jrames commented 3 weeks ago

I'm testing out Local Snapshot Generation. I was able to get it working in a simple repo, but in my primary application all of the generated tests fail with the following:

failed - Error Error Domain=UISceneErrorDomain Code=101 "The current windowing mode does not allow for programmatic changes to interface orientation." UserInfo={NSLocalizedDescription=The current windowing mode does not allow for programmatic changes to interface orientation.}

I tried drastically simplifying things by returning a single very simple Preview via snapshotPreviews() and still hit this. It must be related to my project config in some way but I'm not sure. I'm also running on a sim and have tried a few different ones. Any ideas / suggestions would be appreciated.

noahsmartin commented 3 weeks ago

Hey @jrames There are a couple things I can think of here. First, are any of your previews directly setting the orientation with previewOrientation(...) If not it would default to portrait and should never attempt to change orientation assuming your simulator is already in portrait. If this is the case, can you try adding a breakpoint in UIKitRenderingStrategy around line 47 and see what the difference is between targetOrientation and windowScene.interfaceOrientation?

Also, are you running on an iPad? If so the app needs to have "UIRequiresFullScreen" set to true in Info.plist in order to programmatically rotate. If you run it on an iPhone it shouldn't have this issue.

Also can you check if you are overriding this method? https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623107-application