[英]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.