iPhone Auto-Lock을 지연하지만 비활성화하지는 않습니다
-
06-07-2019 - |
문제
나는 현재 유일한 상호 작용이 iPhone을 흔드는 매우 간단한 앱을 가지고 있습니다. 그러나 iPhone이 터치 이벤트를 얻지 못하기 때문에 결국 화면이 희미 해지고 자동 잠금이 어둡습니다. 흔들릴 때 자동 잠금 시간을 재설정 할 수있는 방법이 있는지 궁금합니다.
자동 잠금을 완전히 비활성화하기 위해 다음을 수행한다는 것을 알고 있습니다.
[[ UIApplication sharedApplication ] setIdleTimerDisabled: YES ]
그러나 나는 그것을 완전히 비활성화하고 싶지 않습니다. iPhone이 합법적으로 사용되지 않으면 예상대로 자동 잠금해야합니다.
당신의 도움을 주셔서 감사합니다.
해결책
값을 전환 할 수 있습니다 [UIApplication sharedApplication].idleTimerDisabled
자신의 nstimer 또는 행동 적 제스처의 가치 (전화를 흔드는)의 가치에 따라. 설정할 수 있습니다 YES
/NO
응용 프로그램에서 여러 번.
다른 팁
다음은 제 앱에서 사용하는 코드입니다. 약간의 배경 : 내 앱에는 내장 웹 서버가있어 사용자가 WiFi를 통해 브라우저에서 데이터에 액세스 할 수 있고 요청이 서버에 도착할 때마다 잠금 타이머를 확장합니다 (이 경우 최소 2 분 동안. 다시 활성화되면 기본 시간이 추가됩니다).
// disable idle timer for a fixed amount of time.
- (void) extendIdleTimerTimeout
{
// cancel previous scheduled messages to turn idle timer back on
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(reenableIdleTimer)
object:nil];
// disable idle timer
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
// re-enable the timer on after specified delay.
[self performSelector:@selector(reenableIdleTimer) withObject:nil afterDelay: 60 * 2];
}
- (void) reenableIdleTimer
{
sharedApplication].idleTimerDisabled );
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(reenableIdleTimer)
object:nil];
// disable idle timer
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}
제휴하지 않습니다 StackOverflow