我正在为客户开发一个后台运行的应用程序。
这不是一个应用商店应用程序,因此它没有像应用商店应用程序通常适用的规则。即使这个应用程序使用私有API也可以,但它必须在未越狱的设备上运行。(该应用程序将是企业级应用程序)
该应用程序需要知道当前设备的方向。看似简单,但实际上并不是。我正在使用您期望的普通代码:
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
BOOL inLandscape = UIDeviceOrientationIsLandscape(deviceOrientation);
然而,似乎这将返回应用程序从前台切换到后台时生效的方向。
我需要跟踪实际设备方向的方向。实际上,我真正想要的是当前前台应用程序的用户界面方向,但苹果公司让推断变得非常困难。如果必须,我会接受设备方向。
该应用程序是用Objective-C编写的,但我也“说Swift”,因此以任一语言表达的答案均可。
deviceOrientation
属性(https://github.com/nst/iOS-Runtime-Headers/search?utf8=%E2%9C%93&q=deviceorientation),还有一个名为`currentDeviceOrientationAllowingAmbiguous:`的私有`UIDevice`方法,当然还有`[UIApplication -statusBarOrientation]`。你试过它们中的任何一个吗? - Aaron BragerCMMotionManager
来计算设备方向。 - Aaron BragerapplicationWillEnterForeground:
中可以检查设备方向。 - William Smith