2012-02-05 91 views
0

我有這個應用程序,監視你整天的一天。將設備放入口袋時,使用接近傳感器關閉屏幕可節省電量。我的問題是它仍然沒有保存足夠的電量,所以我正在嘗試檢測接近狀態何時發生變化,接近度監控將被禁用。這給我帶來了更多問題,因爲接近度監控將停止,但直到您發現傳感器。 這是我的代碼。
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"); 
} 

回答

1

嘗試使用類似如下禁用它的dealloc方法:

-(void)dealloc{ 
    [[UIDevice currentDevice] setProximityMonitoringEnabled:NO]; 
} 
+0

無需調用[超級的dealloc]的功能,你不應該創建一個dealloc的功能。 – Bastian 2012-02-16 13:18:33

+0

@Bastian除非您使用ARC,否則禁止顯式調用dealloc。 – Jonathan 2012-10-12 21:44:02

+0

這是正確的。 :) – Bastian 2012-10-13 12:58:22