将用户位置发送到服务器(Web文件)甚至应用程序已关闭或终止或终止iOS Swift

时间:2017-12-25 13:57:38

标签: ios swift location

我想每5分钟将用户当前位置发送到服务器文件,后台正在工作

我的问题是如何在applicationWillTerminate中使用甚至应用程序已关闭或被杀死

var timer = Timer() 
func applicationDidEnterBackground(_ application: UIApplication) {
    timer.invalidate() // just in case this button is tapped multiple times

     timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)

}


func timerAction() {

     //call the location manger to update the location to the server
}

func applicationWillTerminate(_ application: UIApplication) {

//need code to call continuously  even app closed

}

1 个答案:

答案 0 :(得分:0)

到目前为止,Apple尚未提供在应用处于非活动状态时跟踪用户位置的工具。因此,当应用处于非活动状态或被终止或终止时,您无法跟踪用户的位置。