当didUpdateToLocation收到消息时,我在后台允许做什么? [英] What am I allowed to do in the background when didUpdateToLocation receive a message?

查看:87
本文介绍了当didUpdateToLocation收到消息时,我在后台允许做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解,我的应用程序将收到该方法的消息:

As I understand it, my app will receive messages to the method:

- (void) locationManager:(CLLocationManager *)manager
         didUpdateToLocation:(CLLocation *)newLocation 
         fromLocation:(CLLocation *)oldLocation

即使它在后台(如果我设置正确)。

even when it is in the background (if I set up it right).

我在这种方法中允许做什么?我想可以存储coords等,但是我可以发出服务器请求并传递我的坐标吗?

What am I allowed to do in this method? I guess it is okay to store the coords etc., but can I make a server request and pass along my coordinates with it?

推荐答案

您可以使用标准位置服务,这也要求您将应用声明为需要在plist中执行不间断的后台执行。这将允许您的应用程序在后台无限期执行,但需要耗费大量电力资源。您可以进行Web服务调用或提供与用户交互的其他方式。

You could use the standard location service, which would also require you to declare your app as requiring nonstop background execution in the plist. This would allow your app to execute indefinitely in the background at the cost of significant power resources. You could make web service calls or provide other ways to interact with the user.

非导航应用程序的第二种推荐方法是使用重要更改位置只有在用户位置发生重大变化时才会将应用程序唤醒到后台模式的服务。在这种情况下,您将获得有限的时间来完成代码执行,并且不建议进行Web服务调用,因为它们可能无法在有限时间内完成并导致应用程序被操作系统终止。

The second, and recommended approach for non navigation apps, is to use the significant-change location service which only 'wakes' up your app into the background mode when there are significant changes to the user's location. In this case, you get a finite amount of time to complete code execution and it is NOT recommended to make web service calls as they might not complete in the finite time and cause the app to be terminated by the OS.

有关详细信息,请参阅 iOS应用程序编程指南
以及位置感知编程指南

For more information, refer to the iOS Application Programming Guide and also the Location Awareness Programming Guide

这篇关于当didUpdateToLocation收到消息时,我在后台允许做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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