以编程方式自动锁定 iPhone [英] Auto Lock iPhone programmatically

查看:61
本文介绍了以编程方式自动锁定 iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on an alarm app, which needs to auto-lock the device after a particular time period, since most of the clock applications in the App Store have that feature.

推荐答案

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

If you would like to lock the phone after 5 minutes then do the following:
set this: [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
and also set a timer: [NSTimer scheduledTimerWithTimeInterval:240 target:self selector:@selector(disableIdleTimer) userInfo:nil repeats:NO];
And in the disableIdleTimer method you will set this: [[UIApplication sharedApplication] setIdleTimerDisabled:NO];

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

This will work with the following condition: the iPhone's autolock function is set to the minimum (1 minute).

正如我目前所见,没有更好的方法.

As I see in the moment, there is no better method.

这篇关于以编程方式自动锁定 iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆