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];
}
}
Written by Bolo Michelin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#