2
0

prepare_ios.mm 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * prepare_ios.mm, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "prepare_p.h"
  12. #import <UIKit/UIKit.h>
  13. #include <objc/runtime.h>
  14. namespace
  15. {
  16. UIInterfaceOrientationMask swizzled_supportedInterfaceOrientationsForWindow
  17. (id __unused self, SEL __unused _cmd, UIApplication * __unused application, UIWindow * __unused _Nullable window)
  18. {
  19. if(UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
  20. return UIInterfaceOrientationMaskAll;
  21. return UIInterfaceOrientationMaskLandscape;
  22. }
  23. }
  24. namespace launcher
  25. {
  26. void prepareIos()
  27. {
  28. auto sel = @selector(application:supportedInterfaceOrientationsForWindow:);
  29. auto methodDesc = protocol_getMethodDescription(@protocol(UIApplicationDelegate), sel, NO, YES);
  30. auto appDelegateClass = object_getClass(UIApplication.sharedApplication.delegate);
  31. [[maybe_unused]] auto existingImp = class_replaceMethod(
  32. appDelegateClass, sel, (IMP)swizzled_supportedInterfaceOrientationsForWindow, methodDesc.types);
  33. // also check implementation in qtbase - src/plugins/platforms/ios/qiosapplicationdelegate.mm
  34. NSCAssert(existingImp == nullptr, @"original app delegate has this method, don't ignore it");
  35. }
  36. }