title: Is there a way to check if the iOS device is locked/unlocked?
body: <p>I have used GPS location updates in my application. I want to detect if the iOS device is in sleep mode so that I can turn off the GPS location updates and optimize the battery use. I have already tried pausesLocationupdates in iOS 6, but it does not work as desired.
  I want to turn off the GPS location updates as soon as the device goes to sleep mode. 
  I want to detect the lock/unlock event in the device.</p>
  
  <p>Is there any way to achieve this functionality ?</p>
  
  <p>so far I got the darwin notifications as given below</p>
  
  <pre><code>-(void)registerForall
  {
      //Screen lock notifications
      CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                      NULL, // observer
                                      displayStatusChanged, // callback
                                      CFSTR("com.apple.iokit.hid.displayStatus"), // event name
                                      NULL, // object
                                      CFNotificationSuspensionBehaviorDeliverImmediately);
  
  
      CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                      NULL, // observer
                                      displayStatusChanged, // callback
                                      CFSTR("com.apple.springboard.lockstate"), // event name
                                      NULL, // object
                                      CFNotificationSuspensionBehaviorDeliverImmediately);
  
      CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                      NULL, // observer
                                      displayStatusChanged, // callback
                                      CFSTR("com.apple.springboard.hasBlankedScreen"), // event name
                                      NULL, // object
                                      CFNotificationSuspensionBehaviorDeliverImmediately);
  
      CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                      NULL, // observer
                                      displayStatusChanged, // callback
                                      CFSTR("com.apple.springboard.lockcomplete"), // event name
                                      NULL, // object
                                      CFNotificationSuspensionBehaviorDeliverImmediately);
  
  }
  //call back
  static void displayStatusChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
  {
      NSLog(@"IN Display status changed");
      NSLog(@"Darwin notification NAME = %@",name);
  
  
  }
  </code></pre>
  
  <p>I am able to get the darwin notifications when device is locked/unlocked, but the real problem is how identify between if the notification has come from locking or the unlocking of the device. Console logs are:</p>
  
  <pre><code> LockDetectDemo[2086] &lt;Warning&gt;: IN Display status changed
   LockDetectDemo[2086] &lt;Warning&gt;: Darwin notification NAME = com.apple.springboard.lockcomplete
   LockDetectDemo[2086] &lt;Warning&gt;: IN Display status changed
   LockDetectDemo[2086] &lt;Warning&gt;: Darwin notification NAME = com.apple.springboard.lockstate
   LockDetectDemo[2086] &lt;Warning&gt;: IN Display status changed
   LockDetectDemo[2086] &lt;Warning&gt;: Darwin notification NAME = com.apple.springboard.hasBlankedScreen
   LockDetectDemo[2086] &lt;Warning&gt;: IN Display status changed
   LockDetectDemo[2086] &lt;Warning&gt;: Darwin notification NAME = com.apple.iokit.hid.displayStatus
  </code></pre>
  
  <p>Any private API would also suffice.
  Thanks in advance.</p>