Programmatically lock and unlock iPhone screen

2019-01-02 21:04发布

How do I programmatically lock and unlock the main screen (i.e. the device itself) of an iPhone?

标签: iphone
8条回答
看淡一切
2楼-- · 2019-01-02 21:35

Describe lock and unlock. I would try a switch that enabled = YES and enabled = NO for the view property. So basically you can disable all the UIGestureRecognizers and 'lock' the screen, if this is what you mean. I do it with UIbuttons once I add them as an IBOutlet as well as IBAction, so they are an object and can be modified at the property level. I am working on this very thing right now. I will post my findings.

查看更多
十年一品温如言
3楼-- · 2019-01-02 21:43

It can be done by caling GSEventLockDevice (); from your app. This function can be found in GraphicsServices.framework.

查看更多
姐姐魅力值爆表
4楼-- · 2019-01-02 21:44

It's not possible. However, you can "prevent" your phone from locking when your app is running. [UIApplication sharedApplication].idleTimerDisabled = YES should do it.

查看更多
宁负流年不负卿
5楼-- · 2019-01-02 21:44

I don't believe that there is a way to achieve this.

One thing that i believe is possible is to stop the IPhone from locking. you could then build a view that copied the lock unlock function and you would still have control over the phone.

查看更多
怪性笑人.
6楼-- · 2019-01-02 21:47

This has already been resolved . You can find it on Github: https://github.com/neuroo/LockMeNow (work below IOS 7)

char*framework="/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices";
                void *handle= dlopen(framework, RTLD_NOW);
                if (handle)
                {

                  void (*GSEventLockDevice)() = dlsym(handle, "GSEventLockDevice");

                    if (GSEventLockDevice)
                    {

                        GSEventLockDevice();
                        NSLog(@"Phone is Locked");
                       //.........

                    }
                    dlclose(handle);

                }
查看更多
骚的不知所云
7楼-- · 2019-01-02 21:48

If you want to do this so, Apple never approve this, your app must be jailbreak. you can do this by calling Private framework on your project. you can use GraphicsServices.framework.

NOTE :

This GraphicsServices.framework is a private framework. Apple will never accept your app. By calling GSEventLockDevice() method you can lock or unlock your Device easily. This GSEventLockDevice() resides in the GSEvent.h.

I hope this one helps you.

Please let me know if you still facing any problem

查看更多
登录 后发表回答