How to detect Device Lock and Unlock events in iOS application extension ?

Hey guys,


My iOS application has an extension that detects device Unlock and Lock event. I found 2 separate API to detect. Both of them work great.

But my code is rejected twice by Apple Review Team. The following reason was to reject our binary.


From Apple

Guideline 2.5.1 - Performance - Software Requirements

Your app uses or references the following non-public APIs:


com.apple.springboard.lockcomplete

com.apple.springboard.lockstate


1. First solution to detect device lock and unlock

-----------------------------------Code Starts here-----------------------------------

#import <notify.h> 

int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate",
¬ify_token,
dispatch_get_main_queue(),
^(int token)
{
       uint64_t state = UINT64_MAX;
       notify_get_state(token, &state);
       if(state == 0) {
              self->lastActiveDate = [NSDate date];
              self->deviceCurrentState = _DEVICE_LOCK_STATE_UNLOCKED;
       } else {
              self->deviceCurrentState = _DEVICE_LOCK_STATE_LOCKED;
       }
   }
);

-----------------------------------End of Code-----------------------------------


2. Second solution to detect device lock and unlock


-----------------------------------Code Starts here-----------------------------------

-

(void)registerforDeviceLockNotif
{
//Screen lock notifications
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
     CFBridgingRetain(self), // observer
     displayStatusChanged, // callback
     CFSTR("com.apple.springboard.lockcomplete"), // event name
     NULL, // object
     CFNotificationSuspensionBehaviorDeliverImmediately);


CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
     CFBridgingRetain(self), // observer
     displayStatusChanged, // callback
     CFSTR("com.apple.springboard.lockstate"), // event name
     NULL, // object
     CFNotificationSuspensionBehaviorDeliverImmediately);
}

- (void)removeDeviceLockNotif
{
     CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), CFBridgingRetain(self),      CFSTR("com.apple.springboard.lockstate"), nil);
     CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), CFBridgingRetain(self), CFSTR("com.apple.springboard.lockcomplete"), nil);

}

-----------------------------------End of Code-----------------------------------


Since we are unable above 2 part of codes, what solution or what API we would use to detect device lock and unlock events?


Thank you.

I am curious if you were able to come to a conclusion on this issue? The device lock/unlock notification is an essential feature for the app that I am working on; yet Apple seems to be extremely hesitant to allow 3rd party app's gain this functionality.

Hello,

In my application, I also need to use this feature to detect device lock/unlock state. Have you find other solution?

Thanks.

Any progress?

Issue raise 3 years ago and still no any recommend from apple?

How to detect Device Lock and Unlock events in iOS application extension ?
 
 
Q