Reputation: 43
I have this app that monitors you through out the day. When you place your device in your pocket, the screen will turn off using the proximity sensor to conserve battery. My problem is it still is not conserving enough battery so I am trying to detect when the proximity state changes the proximity monitoring will disable. This brings me more problems because the proximity monitoring will stop but not until you uncover the sensor.
Here is my Code.
- (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");
}
Upvotes: 0
Views: 2528
Reputation: 26
Try to use disable it a dealloc procedure like follows:
-(void)dealloc{
[[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
}
Upvotes: 1