背景位置跟踪无法在物理设备上快速运行 [英] Background location tracking not working on physical device swift

查看:125
本文介绍了背景位置跟踪无法在物理设备上快速运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循本教程( https://www.raywenderlich.com / 92428 / background-modes-ios-swift-tutorial )来创建一个将用户位置映射到后台的应用程序。即使应用程序关闭,用户也会按照用户的位置进行操作,用户按下是,并在后台跟踪位置,每秒更新一次。它可以在模拟器中完美工作,但是可以侧载到物理iPhone 6上,它会停止检查用户在后台的位置。

I followed this tutorial (https://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial) to create an app that maps the user's location in the background. It asks to follow the user's location even when the app is closed, the user presses yes, and it tracks location in the background, updating every second or so. It works perfectly in the simulator, but sideloaded onto a physical iPhone 6, it stops checking the user's location in the background.

推荐答案

我解决了这个问题。如果您的背景位置跟踪在模拟器中运行,但不在运行iOS 9或更高版本的物理电话上运行,则可以通过添加以下代码来修复:

I solved this. If your background location tracking is working in the simulator but not on a physical phone running iOS 9 or later, it is fixed by adding this code:

if #available(iOS 9.0, *) {
            locationManager.allowsBackgroundLocationUpdates = true
        } else {
            // You don't need anything else on earlier versions.
        }

把它放在任何地方,也许放在你的viewdidload中。

Put this anywhere, maybe in your viewdidload.

这篇关于背景位置跟踪无法在物理设备上快速运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆