简体   繁体   English

iPhone多任务处理-如何使“位置”服务更新“用户可选”

[英]iPhone Multitasking - how to make 'location' service updates “user optional”

Considering the impact on battery, I would like to let users decide if the functionality of my app is something they want all the time as in "multitasking/background execution" or just when the app is in the foreground. 考虑到对电池的影响,我想让用户决定我的应用程序的功能是否一直是他们想要的,例如“多任务/后台执行”还是仅在应用程序处于前台时。 Reading this thread: 读取此线程:

How do I get a background location update every n minutes in my iOS application? 如何每隔n分钟在iOS应用程序中获取后台位置更新?

gave me some ideas about what might be the best way to provide a user option to enable the multitasking function. 给了我一些想法,这可能是提供用户选项以启用多任务功能的最佳方法。 I am hoping someone who has considered this dilemma may have a suggestion on the "best way" to go about it. 我希望有人曾考虑过这一难题,可能会对“最佳方式”提出建议。

Problem - Location multitasking is enabled via the plist by setting the UIBackgroundModes item to 'location'. 问题 -通过将UIBackgroundModes项目设置为'location',可以通过plist启用位置多任务。 This is app-wide and permanent. 这是应用程序范围的永久性应用。 How to make the function correspond to a NSUserDefault? 如何使函数对应于NSUserDefault?

Potential Solution A - My proposal goes something like this: 潜在的解决方案A-我的建议是这样的:

- (void)applicationWillResignActive:(UIApplication *)application {
    if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"wantsBackgroundLocationEventProcessing"] ) {
        //Continue using the location subsystem
    } else {
        self.locationManager = nil; //Custom setter does all required cleanup
    }
}

However, my fear is that in this case the app will still receive location events, it simply won't be able to actually do anything with them - the effect on battery life will still be present. 但是,我担心在这种情况下,该应用仍会收到位置事件,它根本无法对其进行任何操作-对电池寿命的影响仍然存在。

Any ideas on how to make UIBackgroundModes 'location' optional during runtime? 关于如何在运行时将UIBackgroundModes的“位置”设置为可选的任何想法?

the setting in plist just tell the iOS you need background update on location WHEN NEEDED. plist中的设置仅告诉iOS您需要在需要时在位置上进行后台更新。 please check out the document here for better understanding. 请在此处查看文档以获得更好的理解。

the [locationManager startUpdatingLocation] will continuously update location change, when you does not need it any more, just use [locationManager stopUpdatingLocation] to turn off GPS to conserve battery. [locationManager startUpdatingLocation]将不断更新位置更改,当您不再需要此更改时,只需使用[locationManager stopUpdatingLocation]关闭GPS以节省电池。

or use [locationManager startMonitoringSignificantLocationChanges] to get notified when significant change happened. 或使用[locationManager startMonitoringSignificantLocationChanges]在发生重大更改时获得通知。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM