背景模式下的iOS区域监控 [英] iOS Region Monitoring in Background Mode

查看:186
本文介绍了背景模式下的iOS区域监控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用区域监控,我遇到了一个问题,我找不到任何答案。区域监控如何在后台模式下工作?

I am using Region Monitoring in my app and I faced a question that I couldn't find any answer to it. How does region monitoring work in background mode?

根据位置意识PG:


每当用户的当前位置
越过边界区域时,系统
为您的应用程序生成适当的区域事件
。如果您的
应用程序已在运行,则这些
事件将直接转发给
任何当前位置管理器对象的代理。
如果您的应用程序没有运行,
系统会在
后台启动它,以便它可以响应。

Every time the user’s current location crosses a boundary region, the system generates an appropriate region event for your application. If your application is already running, these events go directly to the delegates of any current location manager objects. If your application is not running, the system launches it in the background so that it can respond.

现在,这个问题是:我的应用程序处于暂停模式,输入了一个区域并且应该发送一个触发器,此事件是否会直接发送给代理人:

Now, this question is: my app is in the suspended mode, a region has been entered and a trigger should be delivered, does this event will be send "directly" to the delegate's:

locationManager:didEnterRegion:

??同样的问题,如果应用程序处于后台模式。换句话说,在挂起和后台模式下我是否应该考虑接收此事件的代码?或iOS将首先启动应用程序,然后直接将事件发送给代表,而无需任何BG代码?

?? Same question if the app is in background mode. In other words, is there any code I should consider in suspend and background mode to receive this event? or the iOS will first launch the application, then send the event to the delegate directly without any need to BG code?

推荐答案

区域监控如果您在后台,则在您进入受监控区域时重新启动应用程序。

Region monitoring Relaunches your application when you enter the monitored region if you are in background .

然而,您必须在应用重新启动后再次配置您的位置管理器。

however you have to again configure your location manager after the app relaunches .

类似这样的事情 -

something like this -

if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey] ) 
     {

        NSLog(@"Relaunched due to location update");

        NSLog(@"app woke up times ---- %d",ForTest);

        NSLog(@"Starting the location manager");
        self.locmanager = [[CLLocationManager alloc] init];
        [self.locmanager startMonitoringForRegion:(CLRegion)*region];
       // self.locmanager.pausesLocationUpdatesAutomatically = YES ;
    }

这篇关于背景模式下的iOS区域监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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