UnityViewControllerBase+iOS.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. @interface UnityViewControllerBase (iOS)
  3. - (BOOL)shouldAutorotate;
  4. - (BOOL)prefersStatusBarHidden;
  5. - (UIStatusBarStyle)preferredStatusBarStyle;
  6. @end
  7. // we have several ViewController implementations, to better handle all the possible scenarios of setting orientation
  8. // long long ago we had just once controller, handling everything
  9. // then we have found that iOS does not "like" this, or rather it might behave in a way we don't want
  10. // thus we split into one "default" view controller (handling orientation)
  11. // and then per-orientation "fixed orientation" view controllers
  12. // when we were changing orientation forcibly (or autorotation constraints) we were changing view controller to another one
  13. // it turned out later that sometimes (on some devices) iOS 17 does not like this as in it could error/hang
  14. // probably because it ended up having two orientation "processes": one from old controller and another from new one
  15. // for example sometimes it was printing the error message: "A new orientation transaction token is being requested while a valid one already exists"
  16. // thus we are returning back to using just one view controller (on iOS 16+)
  17. // this makes sense especially since in iOS 16 special api to poke iOS about changing autorotation constraint was added
  18. // so we can use it directly (and hope for the best) instead of doing this dance of recreating view controllers
  19. // to support both old and new way without introducing too much copy-paste code, we will tweak
  20. // UnityDefaultViewController to include "forced orientation" field that can be used in determining supported orientations
  21. // should we handle fixed orientation in UnityDefaultViewController is defined by the app (as in, AppController will decide when creating root view controller)
  22. // as we don't want to push the decision that low-level
  23. // view controllers constrained to one orientation
  24. @interface UnityFixedOrientationViewController : UnityViewControllerBase
  25. - (instancetype)initWithOrientation:(UIInterfaceOrientation)interfaceOrientation;
  26. @end
  27. @interface UnityPortraitOnlyViewController : UnityFixedOrientationViewController
  28. @end
  29. @interface UnityPortraitUpsideDownOnlyViewController : UnityFixedOrientationViewController
  30. @end
  31. @interface UnityLandscapeLeftOnlyViewController : UnityFixedOrientationViewController
  32. @end
  33. @interface UnityLandscapeRightOnlyViewController : UnityFixedOrientationViewController
  34. @end
  35. // this is default view controller implementation (autorotation enabled)
  36. // it also has the ability to support fixed orientation; this will be enabled by AppController when creating view controller on iOS 16+
  37. @interface UnityDefaultViewController : UnityViewControllerBase
  38. - (instancetype)initShouldHandleFixedOrientation:(BOOL)shouldHandleFixedOrientation;
  39. // we have well defined points where we should update supported orientations:
  40. // on init and inside [UnityAppController checkOrientationRequest]
  41. // note that pre iOS 16 the latter will recreate default view controller if supported orientations conflict with the current orientation
  42. // on iOS 16+ we are keeping one view controller and let it handle supported orientations by itself
  43. // this is done as opposed to [UnityDefaultViewController supportedInterfaceOrientations] poking unity for that
  44. // as this might happen in "random" places, out-of-sync with our handling of "orientation constraints were changed at unity side"
  45. - (void)updateSupportedOrientations;
  46. @property (nonatomic,readonly) BOOL willHandleFixedOrientation;
  47. @end
  48. NSUInteger EnabledAutorotationInterfaceOrientations();