以编程方式自动锁定iPhone

时间:2011-09-06 07:44:26

标签: objective-c ios auto-lock

我正在开发一个闹钟应用程序,它需要在特定时间段后自动锁定设备,因为App Store中的大多数时钟应用程序都具有该功能。

1 个答案:

答案 0 :(得分:1)

如果您想在5分钟后锁定手机,请执行以下操作:
设置此:[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
并设置一个计时器:[NSTimer scheduledTimerWithTimeInterval:240 target:self selector:@selector(disableIdleTimer) userInfo:nil repeats:NO];
在disableIdleTimer方法中,您将设置:[[UIApplication sharedApplication] setIdleTimerDisabled:NO];

这将适用于以下条件:iPhone的自动锁定功能设置为最小值(1分钟)。

正如我现在所看到的,没有更好的方法。