Bronze Challenge : Proximity Nofication

Posted on

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];
    }
}

Leave a Reply

Your email address will not be published.