Ios 最小化DidFinishLaunchwithOptions启动选项位置密钥发现上的进程?
我的应用程序中新实现了位置处理,在前台和后台进行了测试,结果令人满意。该应用程序正在监视重要的位置变化以及几个区域。我还没有弄清楚,当应用程序被暂停或终止时,我是否会得到同样的结果。 据我所知,当应用程序从这些状态中唤醒时,除了launchOptions Location键将在launchOptions Dictionary参数中找到外,应用程序就好像刚刚启动一样。我的问题是,我可以允许应用程序代理正常运行并假设一切正常吗?是否需要截取所有视图设置代码 didFinishLaunchingWithOptions:launchOptions方法的第一行是:Ios 最小化DidFinishLaunchwithOptions启动选项位置密钥发现上的进程?,ios,ios5,cllocationmanager,uiapplicationdelegate,Ios,Ios5,Cllocationmanager,Uiapplicationdelegate,我的应用程序中新实现了位置处理,在前台和后台进行了测试,结果令人满意。该应用程序正在监视重要的位置变化以及几个区域。我还没有弄清楚,当应用程序被暂停或终止时,我是否会得到同样的结果。 据我所知,当应用程序从这些状态中唤醒时,除了launchOptions Location键将在launchOptions Dictionary参数中找到外,应用程序就好像刚刚启动一样。我的问题是,我可以允许应用程序代理正常运行并假设一切正常吗?是否需要截取所有视图设置代码 didFinishLaunchingWit
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
//Handle Error
}
self.sharedLocationHandler = [[[TTLocationHandler alloc] init] autorelease];
self.siteLogger = [[[ProjectSiteLogger alloc] initWithOptions:nil] autorelease];
self.siteLogger.locationHandler = self.sharedLocationHandler;
self.siteLogger.managedObjectContext = context;
很可能,这涵盖了我响应定位事件所需的所有内容。我可以很容易地在launchOptions中测试location键,并跳过该方法的整个剩余部分,尽管我不确定这可能会带来哪些不可预见的复杂情况。
我还质疑,如果用户在应用程序处于完全未设置视图的不完整状态时故意启动应用程序,会产生什么结果
这是已经尝试过的东西吗,甚至有必要吗?我不知道如何测试它,因为我不知道在应用程序挂起时如何保持与Xcode调试器的连接
---其他更新信息----
最初的测试是在随身携带测试手机的一天,我的位置处理似乎完成了我希望它完成的所有任务,没有对appDelegate进行任何更改。因此,我假设出现了suspend/term唤醒,并执行了完整的appDelegate过程,即使没有任何视图控制器可见。
因此,虽然似乎不需要更改启动过程,但是否仍存在性能或电池问题,这将使缩短appDelegate过程并最小化处理变得谨慎?经过一番测试和调整后,我发现:
// Initialize a flag
BOOL needsViewsSetup = YES;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// All my response to location events are handled in the these two classes
self.sharedLocationHandler = [[[TTLocationHandler alloc] init] autorelease];
self.siteLogger = [[[ProjectSiteLogger alloc] initWithOptions:nil] autorelease];
self.siteLogger.locationHandler = self.sharedLocationHandler;
self.siteLogger.managedObjectContext = self.managedObjectContext;
// check launchOptions, skip all the views if there we were woken by location event
if (![launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
[self confirmDataExistsAtStartup];
[self setupTabbarWithViews];
}
return YES;
}
然后您就可以进行视图设置:
-(void)setupTabbarsWithViews
{
// Code to setup initial views here
// ending with flag toggle to prevent repeat processing
needsViewsSetup = NO;
}
在应用程序中,将进入前台:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
if (needsViewsSetup) {
[self setupTabbarWithViews];
}
}
注意:我的应用程序没有在后台运行位置服务,只侦听重要的位置更改和地理围栏。经过一番测试和调整后,我发现:
// Initialize a flag
BOOL needsViewsSetup = YES;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// All my response to location events are handled in the these two classes
self.sharedLocationHandler = [[[TTLocationHandler alloc] init] autorelease];
self.siteLogger = [[[ProjectSiteLogger alloc] initWithOptions:nil] autorelease];
self.siteLogger.locationHandler = self.sharedLocationHandler;
self.siteLogger.managedObjectContext = self.managedObjectContext;
// check launchOptions, skip all the views if there we were woken by location event
if (![launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
[self confirmDataExistsAtStartup];
[self setupTabbarWithViews];
}
return YES;
}
然后您就可以进行视图设置:
-(void)setupTabbarsWithViews
{
// Code to setup initial views here
// ending with flag toggle to prevent repeat processing
needsViewsSetup = NO;
}
在应用程序中,将进入前台:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
if (needsViewsSetup) {
[self setupTabbarWithViews];
}
}
注意:我的应用程序没有在后台运行位置服务,只侦听重要的位置更改和地理围栏