Programmatically lock and unlock iPhone screen

Solution 1:

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

Solution 2:

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

Solution 3:

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);

                }

Solution 4:

It is probably possible with undocumented Apple functions (maybe GSEventLockDevice() ?) but it certainly leads to automatic App Store REJECTION.

Apple simply don't want anyone to fiddle with core functionalities like this.