我有这个应用程序,可以监控你的一天。将设备放入口袋时,屏幕将使用接近传感器关闭以节省电池电量。我的问题是它仍然没有节省足够的电池,所以我试图检测接近状态何时改变接近监测将禁用。这给我带来了更多问题,因为接近监控将停止,但直到你揭开传感器。
这是我的代码。
- (void)viewDidLoad{
[super viewDidLoad];
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
[[UIDevice currentDevice] proximityState];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange) name:UIDeviceProximityStateDidChangeNotification object:nil];
[self curTime];
}
-(void)proximityStateDidChange{
[[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
NSLog(@"Disabled");
}
答案 0 :(得分:1)
尝试使用禁用它的dealloc过程,如下所示:
-(void)dealloc{
[[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
}