iPhone 近距离监控
我有这个应用程序可以全天监控您。当您将设备放入口袋时,屏幕将使用接近传感器关闭以节省电池。我的问题是它仍然没有节省足够的电池,所以我试图检测接近状态何时发生变化,接近监控将禁用。这给我带来了更多问题,因为接近监控将停止,但直到您揭开传感器为止。 这是我的代码。
- (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");
}
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用如下所示的解除分配过程来禁用它:
Try to use disable it a dealloc procedure like follows: