在我正在处理的iOS应用中,即使应用关闭,我也需要能够确定用户是否在企业中。基本前提是用户将选择一个位置(麦当劳,沃尔玛,银行等),然后当他们走进所选位置时,应用程序将提醒他们并提供行动呼吁(无法真正详细说明行动是什么)。现在,我正在使用Google Places API并使用Core Location查找距离用户当前位置最近的商家。这有效,但仅在应用程序打开时才有效。我想知道是否有任何方法可以使用Passbook,因为它能够确定用户何时走进某个位置。但是,我不确定我能做到这一点,因为我没有用户可能选择的任何机构。有关框架,方法等的任何建议吗?感谢
答案 0 :(得分:2)
如果您想要监视的位置有限,可以使用:
CLLocationManager
- startMonitoringForRegion:
"应用最多可以一次注册20个地区。"
答案 1 :(得分:0)
重点。关闭应用程序后,您无法执行任何操作,直到用户启动它(单击应用程序图标)或系统启动它(例如,当存在voIP要求时)。
您可以参考背景中的应用程序(它是由用户启动的,然后点击主页按钮)
对于您想要的功能,您可以实现UIApplicationDelegate方法以在后台激活和停用位置管理器。
e.g。您可以组合一个NSTimer来触发每个间隔以激活位置,然后停止位置管理器,以避免消耗电池
- (void)applicationDidEnterBackground:(UIApplication *)application {
[NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(launchLocationManager) userInfo:nil repeats:YES]
}
- (void) launchLocationManager {
myLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
myLocationManager.delegate = self;
[myLocationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
//report location
[myLocationManager stopUpdatingLocation];
}