2

I have a today extension that displays a timer. I want to pause the timer when the screen is locked, but can't figure out how to detect if the screen is locked.

I tried doing this but the file is always readable even when the screen is locked: Finding out if the device is locked, from a Notification Widget

I was able to do this in my app using this but am unable to implement it in a widget: How can I detect screen lock/unlock events on the iPhone?

Community
  • 1
  • 1

2 Answers2

1

The way Today Extensions work, they will not be executing when Notification Center is closed. The method viewDidDisappear will be called when the Today Extension is no longer visible and you can stop your timer there.

duncanc4
  • 1,191
  • 1
  • 9
  • 17
-1

Here's what I ended up doing....

  1. Moved the lock screen detection to the container app

  2. Used notify_get_state (see Is there a way to check if the iOS device is locked/unlocked?)

  3. Ran a background task in the app

Community
  • 1
  • 1
  • and the screen detection works if the app is in background? Which capabilities have you enabeld? – alexsc Aug 05 '16 at 13:07