参考
[1]http://stackoverflow.com/questions/832940/programmatically-lock-and-unlock-iphone-screen
[2]http://stackoverflow.com/questions/4476777/how-to-set-lock-screen-wallpaper-and-ringtone-programmatically-in-iphone?rq=1
[3]http://stackoverflow.com/questions/1679814/iphone-phone-goes-to-sleep-even-if-idletimerdisabled-is-yes
[4]https://github.com/kennytm/iphone-private-frameworks/blob/master/GraphicsServices/GSEvent.h
没有公开的API用来处理是否锁屏,旋转等,以下方法前提都是针对越狱手机。
注:以下方法都未验证可用性、兼容性
1.方法一
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
需要在 didFinishLaunchingWithOptions 调用,如果还是不行,尝试:
[[UIApplication sharedApplication] setIdleTimerDisabled:NO]; [[UIApplication sharedApplication] setIdleTimerDisabled:YES];参考[3]
It can be done by caling GSEventLockDevice (); from your app. This function can be found in GraphicsServices.framework.
调用 GSEventLockDevice (); 实现锁屏,
调用 GSEventResetIdleTimer();可以重置空闲时间,实现禁止锁屏
另外还有个方法 GSEventResetIdleDuration(inta,intb); 不知道怎么用的
3.方法三 ,下面代码是读入ringtone设置,将key改为“”即可。
不好意思,我还未找到 记录自动锁屏时间 的plist 和key
The following code can be used to read the actual ringtone title of custom ringtones (synced by iTunes). NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"]; NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"]; NSArray *keys = [dictionary allKeys]; id key = [keys objectAtIndex:indexPath.row]; NSMutableDictionary *customRingtone = [dictionary objectForKey:key]; NSString *name = [customRingtone objectForKey:@"Name"]; cell.textLabel.text = name;