參考
[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]
2.方法二
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;