0

I'm looking for a way to display a UIAlert on the Iphone screen each time the Iphone goes to screenlock mode.

Is there a way to do that through local notifications without using timers ? Or any other means ? Is there a way to detect when screenlock is triggered ?

Thanks in advance ...

Miky Mike

MK.
  • 33,605
  • 18
  • 74
  • 111
Miky Mike
  • 341
  • 6
  • 17

1 Answers1

1

There is no OS indication that the screen is about to lock, at least not that's available to valid apps.

The applicationWillEnterBackground method of your app delegate will be called if the user locks the screen or the device locks itself, but I don't believe you'll be able to display an alert from there.

Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
  • Since IOS version 4 you can do it thanks to local notifications, but the way Apple has implemented that is that you need to schedule the alerts through timers, which is not what I want. I've also found that there is a way to do it using NSRunLoop for mode NSLoopCommonModes but once again, you have to add a timer. Any tip on that ? – Miky Mike Dec 22 '10 at 13:13
  • I assume you need to schedule it through timers because you're not actually getting a notification, right, just having to check periodically? If that's the case, I know of no way to check something repeatedly other than through timers. – Matthew Frederick Dec 22 '10 at 18:23
  • No, I was just desperate to find a way to display an alertView ONLY when the Iphone was screenlocked, but only Jailbroken Iphones can do that. – Miky Mike Jan 07 '11 at 19:56