iOS 后台位置状态信息不显示

iOS Location status message on background doesn't show

我已经实现了一个像 waze 这样的 CLLocation 来在后台模式下获取用户位置,我想显示像 "incall" 这样的栏,表明我正在获取位置。

不知道为什么栏不显示,我在info.plist这个

Key : NSLocationAlwaysUsageDescription.

我假设您是在谈论状态栏下方出现的蓝色 "navigation" 栏。

只有在使用应用程序进行导航时才会出现。仅在后台获取位置信息的应用不会显示蓝色条(或任何其他颜色条)。

如果您 requestAlwaysAuthorization 该栏将不会出现(因为您可以随时使用定位服务)。该栏仅在您 requestWhenInUseAuthorization 并且应用要求在后台继续接收位置更新时出现。

请参阅 requestWhenInUseAuthorization 的文档(强调已添加):

If the user grants “when-in-use” authorization to your app, your app can start most (but not all) location services while it is in the foreground. (Apps cannot use any services that automatically relaunch the app, such as region monitoring or the significant location change service.) When started in the foreground, services continue to run in the background if your app has enabled background location updates in the Capabilities tab of your Xcode project. Attempts to start location services while your app is running in the background will fail. The system displays a location-services indicator in the status bar when your app moves to the background with active location services.

关于 "location-services indicator" 的这一行在 requestAlwaysAuthorization 的文档中明显缺失。