问题
I am facing one of the requirements where I need to detect if the user is using the iPhone or not. Even if my app is in background then also. So far I've found the following way outs, but none of them points to the unlocking mechanism:
applicationProtectedDataWillBecomeUnavailable
: This will tell if the user has locked/unlocked the device but will work only If a passcode is set.Darwin lock/unlock notifications: Not accepted on AppStore.
Proximity Sensor (
UIDeviceProximityStateDidChangeNotification
): This will only happen if the user is calling.[[UIScreen mainScreen] brightness]
: Can be queried duringapplicationDidEnterBackground
state to check whether phone was locked or home button was pressed. If brightness is greater than 0, it indicates home button was pressed or there was a transition to some other app, when it is 0, it means locked.Using motion sensors: Given the battery drainage, a fairly incorrect approach to check what's the roll of the device or acceleration in a certain coordinate system
UIDeviceOrientationDidChangeNotification
: only works when app is in foreground.What's the technology behind apple's "pick up to wake" implementation: I have seen that iPhone6s brightens the screen when you pick it up. They must be using a more efficient way than accelerometer?
I don't see any other good approaches. Did I miss something?
来源:https://stackoverflow.com/questions/50115099/how-to-determine-iphone-is-being-used-unlocked