Background location tracking not working on physical device swift

橙三吉。 提交于 2019-12-06 12:20:44

问题


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.


回答1:


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.
        }

Put this anywhere, maybe in your viewdidload.



来源:https://stackoverflow.com/questions/36524644/background-location-tracking-not-working-on-physical-device-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!