简体   繁体   English

以编程方式锁定和解锁iPhone屏幕

[英]Programmatically lock and unlock iPhone screen

如何以编程方式锁定和解锁iPhone的主屏幕(即设备本身)?

It's not possible. 这是不可能的。 However, you can "prevent" your phone from locking when your app is running. 但是,您可以在应用运行时“防止”手机锁定。 [UIApplication sharedApplication].idleTimerDisabled = YES should do it. [UIApplication sharedApplication].idleTimerDisabled = YES应该这样做。

It can be done by caling GSEventLockDevice (); 可以通过校准GSEventLockDevice()来完成。 from your app. 通过您的应用。 This function can be found in GraphicsServices.framework. 可以在GraphicsServices.framework中找到此功能。

This has already been resolved . 这已经解决了。 You can find it on Github: https://github.com/neuroo/LockMeNow (work below IOS 7) 您可以在Github上找到它: https : //github.com/neuroo/LockMeNow (在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);

                }

It is probably possible with undocumented Apple functions (maybe GSEventLockDevice() ?) but it certainly leads to automatic App Store REJECTION. 可能存在未记录的Apple函数(也许是GSEventLockDevice()吗?),但它肯定会导致自动App Store拒绝。

Apple simply don't want anyone to fiddle with core functionalities like this. 苹果根本不想让任何人摆弄这样的核心功能。

If you want to do this so, Apple never approve this, your app must be jailbreak. 如果您想这样做,Apple绝对不会批准,您的应用程序必须越狱。 you can do this by calling Private framework on your project. 您可以通过在项目上调用专用框架来实现。 you can use GraphicsServices.framework . 您可以使用GraphicsServices.framework

NOTE : 注意 :

This GraphicsServices.framework is a private framework. GraphicsServices.framework是私有框架。 Apple will never accept your app. 苹果将​​永远不会接受您的应用程序。 By calling GSEventLockDevice() method you can lock or unlock your Device easily. 通过调用GSEventLockDevice()方法,您可以轻松锁定或解锁设备。 This GSEventLockDevice() resides in the GSEvent.h . GSEventLockDevice()驻留在GSEvent.h

I hope this one helps you. 希望这对您有所帮助。

Please let me know if you still facing any problem 如果您仍然遇到任何问题,请告诉我

it basically isn't possible because this probably is part of the private frameworks which can be used by Apple only. 基本上是不可能的,因为这可能是只能由Apple使用的私有框架的一部分。 There are apps such as the fake caller apps that utilize a "fake" lockscreen but as you've pointed out, pressing the home button quits the app, rendering your lock screen useless. 有些应用程序,例如伪造的来电者应用程序,都利用了“伪”锁屏,但是正如您所指出的那样,按下主屏幕按钮会退出该应用程序,从而使锁屏无用。

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. 我认为可能的一件事是阻止iPhone锁定。 you could then build a view that copied the lock unlock function and you would still have control over the phone. 然后,您可以构建一个复制了锁定解锁功能的视图,并且您仍然可以控制手机。

Describe lock and unlock. 描述锁定和解锁。 I would try a switch that enabled = YES and enabled = NO for the view property. 我会尝试为view属性启用= YES并启用= NO的开关。 So basically you can disable all the UIGestureRecognizers and 'lock' the screen, if this is what you mean. 因此,基本上,您可以禁用所有UIGestureRecognizers并“锁定”屏幕(如果这是您的意思)。 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. 一旦将它们添加为IBOutletIBAction ,就使用UIbuttons ,因此它们是一个对象,可以在属性级别进行修改。 I am working on this very thing right now. 我现在正在做这件事。 I will post my findings. 我将发表我的发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM