简体   繁体   English

ios-背景中的位置

[英]ios - Cllocation in background

I am working on project in which I need to fire notification when user reaches particular place, even application in background. 我正在研究需要在用户到达特定位置(甚至是后台应用程序)时发出通知的项目。 What is the best way to do this? 做这个的最好方式是什么?

What I found is following. 我发现以下内容。

locationManager = [CLLocationManager new];
[locationManager startUpdatingLocation];

or 要么

[sharedService.locationManager stopMonitoringSignificantLocationChanges];

or 要么

[locationManager startMonitoringForRegion:region];

About startUpdatingLocation I am getting continuous notification on simulator and on ipod after 3-4 mins. 关于startUpdatingLocation我会在3-4分钟后收到有关模拟器和ipod的持续通知。 Documents says it will drain battery and appstore may not accept because this methods must be used by application like navigation types. 文件说它将耗尽电池,并且应用商店可能不接受,因为这种方法必须由导航类型之类的应用程序使用。

About stopMonitoringSignificantLocationChanges documents says it uses cellular network. 关于stopMonitoringSignificantLocationChanges文档说它使用蜂窝网络。 I am not sure whether it wil work on ipod. 我不确定它是否可以在ipod上运行。 On my ipod not working. 在我的iPod上无法正常工作。 Does this method needs sim card? 此方法需要SIM卡吗? And how does this method works? 这种方法如何工作? Means should I walk some distance to get this method respond? 我应该走一段距离才能使此方法响应吗? I traveled 1-2 km but it did not work. 我旅行了1-2公里,但没有成功。

About startMonitoringForRegion I used 关于我使用的startMonitoringForRegion

if([CLLocationManager regionMonitoringEnabled])
        NSLog(@"monitering enable");
    else
        NSLog(@"monitering not avail");

For Ipod I got monitering not avail . 对于Ipod,我没有monitering not avail Also client checked on his iphone. 客户也检查了他的iPhone。 He also did not got notification. 他也没有收到通知。

Please can some one explain me this method? 请有人能解释一下这种方法吗? If any other way of finding location in background then please tell. 如果在后台找到其他位置的方法,请告知。

Edit: I am using startUpdatingLocation. 编辑:我正在使用startUpdatingLocation。 On device it calls didUpdateToLocation method every after 5 mins. 在设备上,每隔5分钟就会调用didUpdateToLocation方法。 Will it use lot of battery? 它会消耗大量电池吗? and appstore will accept this? 并且appstore会接受吗?

If I use startUpdatingLocation will appstore accept app? 如果我使用startUpdatingLocation,appstore会接受该应用程序吗? Since my need is just to give notification when user reach a particular place. 因为我只需要在用户到达特定位置时发出通知。

According to the application requirement you describe I think that - startMonitoringForRegion: is the best approach, look at Apple Doc snippet below... 根据您描述的应用程序需求,我认为-startMonitoringForRegion:是最好的方法,请查看下面的Apple Doc代码段...

You can use the region-monitoring service to be notified when the user crosses a region-based boundary. 当用户越过基于区域的边界时,可以使用区域监视服务得到通知。 Region monitoring applies both to geographical regions (represented by the CLCircularRegion class) and to beacon regions (represented by the CLBeaconRegion class). 区域监视适用于地理区域(由CLCircularRegion类表示)和信标区域(由CLBeaconRegion类表示)。 You region monitoring to detect boundary crossings of the specified region and you use those boundary crossings to perform related tasks. 您进行区域监视以检测指定区域的边界线,并使用这些边界线执行相关任务。 For example, upon approaching a dry cleaners, an app could notify the user to pick up any clothes that had been dropped off and are now ready. 例如,在接近干洗店时,应用程序可以通知用户拿起已经掉落的衣服,现在已经准备好了。

You app is not tracking or routing related application so using [locationManager startUpdateLocation] will be overly done I think. 您的应用程序没有跟踪或路由相关的应用程序,因此我认为使用[locationManager startUpdateLocation]可能会做得过多。

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

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