我知道,我们可以称之为GSEventLockDevice ();从GraphicsServices.framework锁定屏幕iOS 6及以上版本,如解释H2CO3 这里.但不幸的是,它没有奏效iOS 7.
我的问题:
如何以编程方式锁定iPhone屏幕iOS 7?
注意: 我不希望这个用于Appstore.
我试图在给定的时间段后自动锁定设备.我见过的唯一能让这成为可能的是这样做:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
UIApplication.sharedApplication().idleTimerDisabled = true
NSTimer.scheduledTimerWithTimeInterval(30, target: self, selector: "lockScreen", userInfo: nil, repeats: false)
return true
}
func lockScreen() {
print("locking screen")
UIApplication.sharedApplication().idleTimerDisabled = false
}
Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用.还有其他选择吗?市场上有一款名为CellControl的应用程序可以做到这一点,所以我知道它是可能的,似乎无法弄清楚如何.
我也试过从这个答案中取得的obj-c
这是他们的应用程序工作的剪辑,从公共应用程序商店下载.您可以看到,只要我按下主页按钮并退出应用程序,它们就会强行锁定屏幕.
我也看到使用私有框架,这肯定会要求拒绝:
char *gsDylib = "/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices";
void *handle = dlopen(gsDylib, RTLD_NOW);
if (handle) {
BOOL locked = FALSE;
void (*_GSEventLockDevice)() = dlsym(handle, "GSEventLockDevice");
if (_GSEventLockDevice) {
_GSEventLockDevice();
//...
}
dlclose(handle);
//... …Run Code Online (Sandbox Code Playgroud) ios ×3
iphone ×2
objective-c ×2
c# ×1
ios7 ×1
lockscreen ×1
swift ×1
xamarin ×1
xamarin.ios ×1