【问题标题】:Send user location to server(web file) even app is closed or terminated or kill for iOS Swift将用户位置发送到服务器(网络文件),即使应用程序已关闭或终止或杀死 iOS Swift
【发布时间】:2017-12-25 22:08:39
【问题描述】:

我想每 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

}

【问题讨论】:

  • 您将无法做到这一点。您不能只跟踪人们的位置。
  • 是否有任何选项可以使应用程序始终在后台运行。不允许用户关闭应用程序,或者如果他们关闭,则使应用程序在后台运行。

标签: ios swift location


【解决方案1】:

到目前为止,Apple 还没有提供在应用处于非活动状态时跟踪用户位置的功能。因此,当应用程序处于非活动状态或被终止或终止时,您无法跟踪用户的位置。

【讨论】:

  • 感谢您的确认
  • 是否有任何选项可以使应用程序始终在后台运行。不允许用户关闭应用程序,或者如果他们关闭,则使应用程序在后台运行。
  • 不幸的是没有办法。参考这个 :: stackoverflow.com/questions/46075103/…
猜你喜欢
  • 2016-04-04
  • 2023-03-14
  • 2016-08-19
  • 2022-10-06
  • 2018-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多