2011-09-16 119 views
1

我有一个关键问题让我与你分享。 我有一个iphone应用程序需要发送当前位置到服务器无论应用程序是在后台模式还是每分钟前景模式。 我做在像背景模式的info.plist参数设置属性 - >位置和位置配置其他代码是通常如何永远在后台模式下运行应用程序?

 
- (CLLocationManager *)loc_mngr { 

    if (loc_mngr != nil) { 
     return loc_mngr; 
    } 


    loc_mngr = [[CLLocationManager alloc] init]; 
    loc_mngr.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 
    loc_mngr.delegate = self; 
    return loc_mngr; 

} 

loc_mngr是CLLocationManager的对象。 委托方法实现完成。 它适用于我,但问题是如何当我的应用程序在后台上启用位置服务启用。 请问我该如何处理它? 谢谢你。

+0

抱歉,但我不明白的条款提出你的意见你的意思是什么。 –

回答

0

您将需要创建一个CLLocationManagerDelegate以接收应用程序的回调。您需要设置位置项目才能运行,并且当您的应用转到后台时,您需要让代理“侦听”位置更新。这可以通过区域监控-didEnterRegion或-didExitRegion。或者像标准位置监视中的-dUpUpdateToLocation一样简单。

欲了解更多信息,请阅读Apple's Location Awareness Programming Guide。祝你好运。

0

术语“永远”在概念上是错误的:苹果保留随时杀死应用程序的权利。你需要重新考虑逻辑。

一些注意事项:

  • 这是错误的,保持本地化(标准定位)总是在:它消耗的电池非常quicky

  • 是更好地使用:

    [的LocationManager startMonitoringSignificantLocationChanges] ;

    这样功耗要少得多(即使精密度较低...)

  • 使用地区:即使您的应用程序被打死/终止他们服从了。 (我们测试它在io5中,它的工作原理)
2

看看this apple document,你有以下方法来做这件事情。

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(0.0, 0.0); 
CLRegion *region = [[CLRegion alloc] initWithCircularRegionWithCenter:coord radius:500 identifier:@"Some Identifier"]; 

,然后与框架注册区域:

[locationManager startMonitoringForRegion:region]; 

委托协议定义了三种方法来使用的国家和地区:

– locationManager:didEnterRegion: 
– locationManager:didExitRegion: 
– locationManager:monitoringDidFailForRegion:withError: 
相关问题