当我在应用程序 didFinishLaunchingWithOptions 中收到 UIApplicationLaunchOptionsLocationKey 时,是否初始化 viewController?

发布于 2024-11-05 23:16:47 字数 340 浏览 4 评论 0原文

我正在创建一个应用程序,它侦听重要的位置更改事件,如果应用程序终止,iOS 将启动设置了 UIApplicationLaunchOptionsLocationKey 的应用程序。

因此,文档说要创建一个新的位置管理器并再次注册位置更新。但是,没有提到我是否应该初始化我的 viewController (就像我在正常的应用程序启动中所做的那样)?我的视图控制器在 viewDidLoad 中初始化,但在 appDidFinishLaunchingWithOptions 中创建。

知道操作系统为应用程序提供了多少时间来处理位置更新吗?如果位置更改表明应用程序感兴趣的位置,我的应用程序需要发出 Web 服务请求。

谢谢

I'm creating an app which listens to significant location change events and in case the app gets terminated then the iOS launches the app with UIApplicationLaunchOptionsLocationKey set.

So, the documentation says to create a new location manager and register for location updates again. However, doesn't mention if I'm supposed to initialize my viewController (as I do in normal app launch as well)? My view controllers initialize in viewDidLoad but are created in appDidFinishLaunchingWithOptions.

Any idea how much time does OS provides to the App for location update handling? My app needs to make a webservice request if the location change indicates an interested location for the app.

Thanks

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

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

发布评论

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

评论(1

暮光沉寂 2024-11-12 23:16:47

您应该考虑将初始化代码移至新方法,例如 initializeViews。此方法将检查以确保视图尚未初始化,然后初始化它们。您可以从 application:didFinishLaunchingWithOptions:applicationWillEnterForeground: 调用此方法,但 application:didFinishLaunchingWithOptions: 中的调用仅在应用程序未启动时才会发生不会进入后台。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    if([UIApplication sharedApplication].applicationState != UIApplicationStateBackground)
        [self initializeViews];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
    [self initializeViews];
}
- (void)initializeViews {
    if(!viewsAreInitialized) {
        ...
        viewsAreInitialized = YES;
    }
}

You should consider moving your initialization code to a new method, something like initializeViews. This method would check to make sure the views haven't been initialized and then initialize them. You would call this method from application:didFinishLaunchingWithOptions: and applicationWillEnterForeground:, but the call in application:didFinishLaunchingWithOptions: would only occur if the application wasn't going to the background.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    if([UIApplication sharedApplication].applicationState != UIApplicationStateBackground)
        [self initializeViews];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
    [self initializeViews];
}
- (void)initializeViews {
    if(!viewsAreInitialized) {
        ...
        viewsAreInitialized = YES;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文