后台模式下的 iOS 区域监控

发布于 2024-11-16 18:42:17 字数 470 浏览 4 评论 0原文

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

根据位置感知 PG 的说法:

每次用户的当前位置 跨越边界区域,系统 生成适当的区域事件 为您的应用程序。如果你的 应用程序已经在运行,这些 活动直接发送至代表 任何当前位置管理器对象。 如果您的应用程序没有运行, 系统将其启动于 背景以便它可以响应。

现在,这个问题是:我的应用程序处于挂起模式,已输入一个区域并且应该传递触发器,此事件是否将“直接”发送到委托的:

locationManager:didEnterRegion:

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

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?

According to Location Awareness 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:

?? 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别挽留 2024-11-23 18:42:17

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

但是,在应用程序重新启动后,您必须再次配置位置管理器。

像这样的东西-

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 ;
    }

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 ;
    }
浅语花开 2024-11-23 18:42:17

据我所知,区域监控仅适用于iPhone4,并且它基于改变通信塔的设备。这样,它使用的电池比标准后台位置更新要少得多。
确保您启用了适当的背景模式。只要您实现了该委托,您就应该准备就绪。

As far as I know region monitoring only works with iPhone4 and it's based on the device changing the communication towers. This way it uses way less battery than the standard background location update.
Make sure you enabled the appropriate background modes. As long as you implement that delegate, you should be ready to go.

2024-11-23 18:42:17

在此处输入图像描述

启用背景模式
启用位置更新和后台获取

enter image description here

enable Background Modes
in that enable Location updates and Background Fetch

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文