gpt4 book ai didi

ios - CLLocationManager 的事件序列

转载 作者:行者123 更新时间:2023-11-29 12:54:29 25 4
gpt4 key购买 nike

我正在阅读 application:didFinishLaunchingWithOptions:方法并从 NSHipster 中发现以下代码:

@import CoreLocation;

@interface AppDelegate () <CLLocationManagerDelegate>
@property (readwrite, nonatomic, strong) CLLocationManager *locationManager;
@end

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...

if (![CLLocationManager locationServicesEnabled]) {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Location Services Disabled", nil)
message:NSLocalizedString(@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled.", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil] show];
} else {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startMonitoringSignificantLocationChanges];
}

if (launchOptions[UIApplicationLaunchOptionsLocationKey]) {
[self.locationManager startUpdatingLocation];
}
}

我已经研究过 this question ,但我仍然对事件的顺序感到困惑。如果我错了请纠正我:

当应用程序首次启动时,CLLocationManager 得到设置(如果启用了位置服务)并开始监视位置的重大变化。当应用程序随后终止时,CLLocationManager 是否会继续监视更改?据我所知,事实并非如此。那么如果有新的定位事件如何启动呢?我知道接下来应用程序将通过传递给 application:didFinishLaunchingWithOptions:UIApplicationLaunchOptionsLocationKey 重新启动。它是在后台完成的吗?现在 CLLocationManager 将首先(再次)进行设置,紧接着 locationManager 将开始根据事件更新位置。之后 CLLocationManager 将继续监视更改。

相关问题:当​​有新的位置事件并且应用程序正在运行(在后台或前台)时,会调用什么委托(delegate)?

最佳答案

当应用程序随后终止时,CLLocationManager 是否会继续监视更改?
-> 你猜对了。 它不是,但您的操作系统监控并知道此应用程序可能需要它,因为您调用了 startMonitoringSignificantLocationChanges:.

你的问题 -我知道接下来应用程序会重新启动,UIApplicationLaunchOptionsLocationKey 传递给 application:didFinishLaunchingWithOptions:。是后台完成的吗?

Ans-> ,

If you start this service and your application is subsequently terminated, the system -automatically relaunches the application into the background if a new event arrives. In such a case, the options dictionary passed to the application:didFinishLaunchingWithOptions: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location event.

当出现新的位置事件并且应用正在运行(在后台或前台)时,会调用什么委托(delegate)?

您提供的链接说明了一切。当您的应用程序在前台或后台运行时,如果一个新的位置事件到达,并且您的应用程序变为事件状态,您的 CLLocationManagerDelegate 仍将被调用。

关于ios - CLLocationManager 的事件序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21494105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com