1

当应用程序打开时,一切正常 100%。但是一旦应用程序关闭,接近传感器也会停止。我到处检查过,这就是我所拥有的。

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Initiates the proximity sensor
    [[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
    [[UIDevice currentDevice] proximityState];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange) name:UIDeviceProximityStateDidChangeNotification object:nil];

    //Background notification
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
}

-(void)applicationDidEnterBackground{
    NSLog(@"Entered background state.");
    [[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
}

当应用程序关闭时,它会打印出“进入后台状态”。但不会一直监控接近传感器。

4

0 回答 0