我有一个 GPS 应用程序,它已经使用了相当多的电池。由于应用程序的性质,我不希望用户在他们不知情的情况下电池没电时丢失所有数据。所以,我想我会监控电池,然后在电池电量很低时保存并停止 GPS 数据。我会使用:
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryStateDidChange:)
name:UIDeviceBatteryStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryLevelDidChange:)
name:UIDeviceBatteryLevelDidChangeNotification
object:nil];
所以,有几个问题:
- 监控电池会导致更多的电池消耗吗?
- 在电池没电之前为用户自动保存(核心数据)是个好主意吗?