Guest User

Untitled

a guest
Jul 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. NSLog(@"didFinishLaunching");
  4.  
  5. // Get the device object and turn proximity monitoring on
  6. UIDevice *d = [UIDevice currentDevice];
  7. [d setProximityMonitoringEnabled:YES];
  8.  
  9. // Get the NSNotificationCenter object
  10. NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
  11.  
  12. // Sign up to receive notifications when the proximity state changes
  13. [nc addObserver:self selector:@selector(proximityChanged:) name:UIDeviceProximityStateDidChangeNotification object:d];
  14. NSLog(@"Observing...");
  15.  
  16. [self.window makeKeyAndVisible];
  17. return YES;
  18.  
  19. }
  20.  
  21. - (void)proximityChanged:(NSNotification *)note {
  22.  
  23. // Print out the changes of proximity state
  24. NSLog(@"Proximity Changed: %d", [[note object] proximityState]);
  25.  
  26. }
Add Comment
Please, Sign In to add comment