Last Updated: February 25, 2016
·
481
· bolomichelin

Bronze Challenge : Proximity Nofication

When a notification is posted, change the background color of HeavyViewController.m

RotationAppDelegate.m

UIDevice *device = [UIDevice currentDevice];
[device setProximityMonitoringEnabled:YES];

// Set up an observer for proximity changes
[[NSNotificationCenter defaultCenter] addObserver:hvc selector:@selector(sensorStateChange:)
                                             name:@"UIDeviceProximityStateDidChangeNotification" object:device];

HeavyViewController.m

- (void)sensorStateChange:(NSNotificationCenter *)notification
    {

    if ([[UIDevice currentDevice] proximityState] == YES){
        NSLog(@"Device is close to user.");
        self.view.backgroundColor = [UIColor grayColor];
    }else{
        NSLog(@"Device is ~not~ closer to user.");
        self.view.backgroundColor = [UIColor whiteColor];
    }
}