ユーザーが耳の近くに電話を持っているかどうかを教えてくれるproximityStateプロパティのチェックを実装します。彼が電話をかけているように。iOS 7 では動作しますが、他の理由でこの機能を削除する必要がありました。iOS 8 では、この機能をアプリに追加し、近接状態が初めて YES に変更された後、永遠に YES のままになります。デバイスを耳から外してもNOにはなりません。iOSのバグのように見えますが、同じ問題を抱えている人が他にもいます。
ありがとう。
ユーザーが耳の近くに電話を持っているかどうかを教えてくれるproximityStateプロパティのチェックを実装します。彼が電話をかけているように。iOS 7 では動作しますが、他の理由でこの機能を削除する必要がありました。iOS 8 では、この機能をアプリに追加し、近接状態が初めて YES に変更された後、永遠に YES のままになります。デバイスを耳から外してもNOにはなりません。iOSのバグのように見えますが、同じ問題を抱えている人が他にもいます。
ありがとう。
この問題は発生しておらず、以下のコードは iOS 8 で動作します。アプリケーションがポートレート モードをサポートしていない場合、近接センサーは監視されないことに注意してください。私のアプリケーションのデリゲート:
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
{
UIDevice *currentDevice;
}
- (BOOL) application: (UIApplication*) application didFinishLaunchingWithOptions: (NSDictionary*) launchOptions
{
NSLog(@"Application finished launching!");
currentDevice = [UIDevice currentDevice];
[currentDevice setProximityMonitoringEnabled:YES];
if (currentDevice.proximityMonitoringEnabled)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onProximitySensorStateChanged:) name:UIDeviceProximityStateDidChangeNotification object:nil];
NSLog(@"Monitoring proximity sensor!");
}
else
{
NSLog(@"Device does not have a proximity sensor!");
}
return YES;
}
- (void) onProximitySensorStateChanged: (NSNotification*) notification
{
if (currentDevice.proximityState)
{
NSLog(@"User is now close to the proximity sensor!");
}
else
{
NSLog(@"User is now away from the proximity sensor!");
}
}
@end