应用程序进入后台后,我需要获取设备方向(纵向、向上、横向、横向),然后通过蓝牙将其发送到另一台设备。[UIDevice currentDevice]。方向在后台模式下不工作。有什么办法我能做到这一点吗?
有一个名为-[UIApplication _getSpringBoardOrientation]
的私有方法,它只调用另一个私有方法-[UIApplication activeInterfaceOrientation]
,它似乎为您提供了当前前台应用程序的方向。
但据我所知,我不认为它会捕捉到背景中的方向变化,因为UIDevice类不能这样工作。但是,当您的应用程序在后台使用进入时,您可以捕捉最后的定向状态
Objective-C
-(void)applicationDidEnterBackground:(UIApplication *)application
Swift
func applicationDidEnterBackground(application: UIApplication)