0

Possible Duplicate:
Programmatically lock and unlock iPhone screen

i.e. A software button that will replicate the hardware screen lock button.

And, can I make a slider that will completely shut down the device?

Community
  • 1
  • 1
  • This is not possible..... – Aman Aggarwal Jan 31 '13 at 06:23
  • So if the hardware button is broken there is no way to make a simple app that would allow the screen to be locked. I know it can be done with the Accessibility options but that solution requires a lot of screen clicks each time you wish to lock the screen. – Toby Heap Jan 31 '13 at 06:30
  • @TobyHeap There is, see my answer, it's just that it's a private API, so you won't be able to submit it to the AppStore. –  Jan 31 '13 at 06:32

2 Answers2

2

You can, it's just a private API and you won't get into the AppStore. Fine in jailbroken or in-house/private apps, though.

extern void GSEventLockDevice();

- (void)lockScreen:(UIButton *)sender
{
    GSEventLockDevice();
}

(Link against the GraphicsServices private framework to use this.)

  • Interesting answer. Still we have to assume that the context of the question is app store legality. Thus your answer is just showing off what tricks you know, but not help. – Cocoanetics Jan 31 '13 at 06:30
  • @Cocoanetics No. Why would we have to assume it? There are tons of questions about JB development here on SO, and anyway OP didn't mention this one is going to the AppStore. This is not a good place to give revenge, you know. I understand you're jealous because I knew something you didn't, but don't be childish. –  Jan 31 '13 at 06:31
  • So how can one lick against that private framework? – Zhao Xiang Jan 31 '13 at 06:36
  • Thanks for the answer. Although I am looking for a 'legal' method it is useful to have the complete picture. – Toby Heap Jan 31 '13 at 06:37
  • @ZhaoXiang Just as someone would normally, but by adding the `PrivateFrameworks` directory to the linker search path. –  Jan 31 '13 at 06:49
  • @TobyHeap You're welcome, I'm glad to have helped. –  Jan 31 '13 at 06:50
0

No. Those functionalities are not exposed by Apple's public APIs. There are possibilities (see other answers) if you don't need App Store legality.

Cocoanetics
  • 8,171
  • 2
  • 30
  • 57
  • -1, "not possible" is just wrong. "Those are not exposed" is wrong as well. –  Jan 31 '13 at 06:25
  • Also, no need for revenge downvoting. I'm right, my answer is technically correct. –  Jan 31 '13 at 06:29