0

我正在使用以下代码来获取设备方向更改通知。

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:[UIDevice currentDevice]];

我的应用程序也在后台运行。

  • 当应用程序在前台运行时,通知工作正常。
  • 如果应用程序处于前台并且设备被锁定,则[[UIDevice currentDevice] orientation]始终返回纵向方向,并且在锁定之前会抛出方向更改通知。
  • 但是当应用程序进入后台时,通知就会停止。之后[[UIDevice currentDevice] orientation]将始终返回它最后在活动状态下测量的方向。

有人可以告诉我为什么当我的应用程序进入仍在使用设备的后台状态(被其他应用程序)时通知会停止吗?我正在收集所有方向更改事件,因此我需要设备在应用程序处于前台或后台时向我发送事件。

4

0 回答 0