0

私は一日中あなたを監視するこのアプリを持っています。デバイスをポケットに入れると、バッテリーを節約するために近接センサーを使用して画面がオフになります。私の問題は、まだ十分なバッテリーを節約していないため、近接状態が変化したときに近接監視が無効になることを検出しようとしています。近接監視は停止しますが、センサーのカバーを外すまで停止しないため、これによりさらに問題が発生します。これが私のコードです。

- (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");
}
4

1 に答える 1

1

次のようなdealloc手順を無効にして使用してみてください。

-(void)dealloc{ 
  [[UIDevice currentDevice] setProximityMonitoringEnabled:NO]; 
 }
于 2012-02-16T11:44:58.837 に答える