当app在后台时,我可以将用户的当前位置发送到服务器吗? [英] Can I send user's current location to server, when app is in background?

查看:189
本文介绍了当app在后台时,我可以将用户的当前位置发送到服务器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当app在后台时,我可以将用户的当前位置发送到服务器吗?
例如:在我的应用程序中,我想每隔2分钟存储用户的当前位置,然后将其当前位置发送到服务器。当应用程序处于后台时,我可以这样做吗?
我可以在后台模式下向服务器发送位置更新吗?

Can I send user's current location to server when app is in background. For example: In my app i want to store the user's current location in every 2min and then send his current location to server. Can I do this when the app is in background? Can I send location updates to the server in background mode and how?

推荐答案

你可以从iOS7开始。您基本上需要提出两种背景状态:位置和提取。

在您的应用中,您将注册gps位置更改,并在每次调用回调时存储它们。然后你将注册:

You can since iOS7. You basically need to ask for two background states: location and fetch.
In your app you'll register for gps location changes, and store them every time your callback is called. Then you'll register for:

 application:performFetchWithCompletionHandler:

这通常用于在后台下载文件,但您可以使用它将数据发布到网络服务器。请注意,您无法控制此调用的频率。

要测试此操作,您可以在Xcode调试菜单中强制在iOS模拟器中执行获取操作。

我能够以这种方式成功跟踪用户位置。
您可以在 Apple doc ,你会找到关于后台获取的教程这里

This is usually used to download files in the background, but you can use it to POST your data to a webserver. Just note that you don't have control on the frequency of this call.
To test this you can force a fetch operation in the iOS simulator, from the Xcode Debug menu.
I was able to track the user position successfully this way. You can find more info in the Apple doc and you'll find a tutorial on the background fetch here

这篇关于当app在后台时,我可以将用户的当前位置发送到服务器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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