Bronze Challenge : Proximity Nofication

Posted on

When a notification is posted, change the background color of HeavyViewController.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];


- (void)sensorStateChange:(NSNotificationCenter *)notification

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

Leave a Reply

Your email address will not be published.