简体   繁体   English

我可以在iPhone上创建后台服务吗?

[英]Can I create a background service on iphone?

I am developing an iphone app. 我正在开发iPhone应用程序。 the iphone which install my app was asked to upload it's location every minute(or hour) to a webservice. 安装我的应用程序的iPhone被要求每分钟(或每小时)将其位置上传到网络服务。 So what should i do with this situation? 那么在这种情况下我该怎么办?

I know there is a corelocation framework, I could use it for my app. 我知道有一个corelocation框架,我可以在我的应用程序中使用它。 like when I run this app, the corelocation will grab the GPS for my. 就像我运行此应用程序时一样,核心位置将为我获取GPS。 my question is what if I close the app? 我的问题是,如果我关闭该应用程序该怎么办? Can i still get the GPS and upload it to webservice every minute? 我还能每分钟获取GPS并将其上传到网络服务吗? If I can't, how could I ? 如果我做不到,那我怎么能?

You could enable background location service, If application is in background and receives a considerable change in location it will activate the app for a brief amount of time, This will give you some time to process. 您可以启用后台位置服务,如果应用程序在后台并且收到位置的重大变化,它将在短时间内激活该应用程序,这将为您提供一些处理时间。 Apple recommends not to use web-service calls during this time, because there wont be any guarantee that the app would be live when it returns back. 苹果建议您在此期间不要使用网络服务呼叫,因为无法保证该应用返回后将继续运行。 But since you just want to update the location, you could just post it and dont have to wait for response. 但是,由于您只想更新位置,因此可以发布它,而不必等待响应。 Please note that significant location change should be used and this will help you to save your device's battery life. 请注意,应使用重要的位置更改,这将帮助您节省设备的电池寿命。 This is when the app is in background state. 这是当应用处于后台状态时。

May be you could try registering for the proximity/location alert or something. 可能是您可以尝试注册接近/位置警报之类的东西。 But i am not sure whether it would help when app is closed. 但我不确定关闭应用程序后是否有帮助。

If your app is running in the background then you can get the GPS data but it the application is removed from the Background then you cannot get the GPS data. 如果您的应用程序在后台运行,则可以获取GPS数据,但是如果该应用程序已从后台删除,则您将无法获取GPS数据。 This is not possible in iPhone. 在iPhone中这是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM