c# - 为什么“后台位置更新”只有在应用重启后才开始工作?
问题描述
- 运行应用程序
- 切换到背景。
- “后台位置更新”在后台启动,但不到一分钟。
- 我单击应用程序图标或返回应用程序,“位置更新”开始工作
- 回到背景。“背景位置更新”现在可以长期使用。
问题是什么?为什么第一次过渡到后台模式“后台位置更新”会在不到 30 秒内停止工作。
public LocationManager()
{
this.locMgr = new CLLocationManager
{
PausesLocationUpdatesAutomatically = false
};
locMgr.AllowsBackgroundLocationUpdates = true;
locMgr.DesiredAccuracy = 1;
locMgr.DistanceFilter = 1;
locMgr.StartUpdatingLocation();
}
我的 info.plist
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>This application needs access to a location.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This application needs access to a location.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This application needs access to a location.</string>
我的 AppDelegate.cs
private CLLocationManager locationManager = new CLLocationManager();
public override void DidEnterBackground(UIApplication application)
{
Manager = new LocationManager();
Manager.StartLocationUpdates();
}
解决方案
推荐阅读
- javascript - 如何从 xyz 世界坐标中获取 xy 屏幕坐标?
- ios - 搜索栏在 Swift 4 IOS 应用程序中不起作用
- ruby-on-rails - ActionController::UnknownFormat 使用自定义操作在带有设计的rails中更改用户密码时
- npm - 错误:使用 webpack 尝试生成战争文件
- c++ - Armadillo 中的模板元编程
- json - 在 django 序列化程序中,JSONField 可以处理具有混合类型值的字典吗?
- java - 如何使用 GSON 反序列化嵌套的 JSON 数组?
- r - 可以在 R 中创建一维命名向量吗?
- python - 编码标准:是否应该总是在每个方法或函数的末尾写“return”?
- ruby-on-rails - 如何简化此路由编码以减少行数?