简体   繁体   English

当我在app didFinishLaunchingWithOptions中收到UIApplicationLaunchOptionsLocationKey时,我是否初始化viewController?

[英]Do I initialize the viewController when I receive UIApplicationLaunchOptionsLocationKey in app didFinishLaunchingWithOptions?

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. 我正在创建一个应用程序来监听重要的位置更改事件,如果应用程序被终止,那么iOS将使用UIApplicationLaunchOptionsLocationKey设置启动应用程序。

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)? 但是,没有提到我是否应该初始化我的viewController(就像我在正常的应用程序启动时一样)? My view controllers initialize in viewDidLoad but are created in appDidFinishLaunchingWithOptions. 我的视图控制器在viewDidLoad中初始化,但是在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. 如果位置更改指示应用程序感兴趣的位置,我的应用程序需要发出Web服务请求。

Thanks 谢谢

You should consider moving your initialization code to a new method, something like initializeViews . 您应该考虑将初始化代码移动到新方法,例如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. 您可以从application:didFinishLaunchingWithOptions:applicationWillEnterForeground:调用此方法,但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;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS - 如何将 arguments 从 didFinishLaunchingWithOptions 传递到 viewController? - iOS - How do I pass arguments from didFinishLaunchingWithOptions to a viewController? 如果没有Storyboard,如何初始化自定义ViewController? - How do I initialize a custom ViewController when there's no Storyboard? 我应该何时使用didFinishLaunchingWithOptions? - When should I use didFinishLaunchingWithOptions? 应用启动时无法从didFinishLaunchingWithOptions访问ViewController - Unable to access viewcontroller from didFinishLaunchingWithOptions when app launches 在制作没有ViewController的应用程序时如何使用RootViewController? - How do I use a RootViewController when making an app without a ViewController? 如何在应用加载时使viewController出现? - How do I make a viewController appear when app loads? 如何在同一ViewController中初始化两个NSObject实例-Swift - How Do I Initialize Two Instances of NSObject in the same ViewController - Swift 如何在ViewController中初始化实例变量和属性 - How do I initialize instance variables and properties in the ViewController 我如何知道应用程序是否通过AppDelegate的didFinishLaunchingWithOptions上的Firebase-Deeplink(动态链接)启动 - How do I know if app was launched via Firebase-Deeplink (Dynamic Links) at AppDelegate's didFinishLaunchingWithOptions 使用UIApplicationLaunchOptionsLocationKey在后台启动应用程序时,NSURLCredentialStorage不返回任何凭据 - NSURLCredentialStorage returns no credential when the app is started in the background with UIApplicationLaunchOptionsLocationKey
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM