iOS에서 프로그래밍 방식으로 절전 모드를 비활성화/활성화하는 방법은 무엇입니까?
카운트다운이 끝날 때까지 깨어 있어야 하는 앱이 있는데, 할당된 취침 시간에 도달할 때마다 '수면 모드'로 전환됩니다.
내 앱에서는 사용자가 절전 모드를 비활성화/활성화할 수 있도록 절전 모드를 연기할 수 있는 옵션이 있습니다.
프로그래밍 방식으로 어떻게 합니까?
다음과 같이 유휴 타이머를 비활성화할 수 있습니다.
목표 C:
[UIApplication sharedApplication].idleTimerDisabled = YES;
Swift에서:
UIApplication.sharedApplication().idleTimerDisabled = true
Swift 3.0 및 Swift 4.0의 경우:
UIApplication.shared.isIdleTimerDisabled = true
다시 설정NO
또는false
절전 모드를 다시 활성화합니다.
예를 들어 보기를 떠날 때까지 필요한 경우 Will Dispose 보기를 재정의하여 다시 설정할 수 있습니다.
override func viewWillDisappear(_ animated: Bool) {
UIApplication.shared.isIdleTimerDisabled = false
}
UIA 응용 프로그램 클래스에 대해 자세히 알아봅니다.
Swift 3에서 유휴 타이머를 비활성화하려면 다음과 같이 하십시오.
UIApplication.shared.isIdleTimerDisabled = true
유휴 타이머를 다시 켜는 방법은 다음과 같습니다.
UIApplication.shared.isIdleTimerDisabled = false
추가로, 주의할 점은YES
그리고.NO
Swift에서는 사용할 수 없으며 다음 중 하나를 사용해야 합니다.true
또는false
(이전 답변과는 대조적으로).
iOS 13, Swift 5,5.1+로 유휴 타이머를 비활성화합니다.인SceneDelegate.swift
.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
UIApplication.shared.isIdleTimerDisabled = true
}
스위프트 3에서 이것이 가능한 정확한 위치는AppDelegate.swift
추가해야 합니다.UIApplication.shared.isIdleTimerDisabled = true
안에서.application
func 결과는 다음과 같습니다.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.isIdleTimerDisabled = true
return true
}
언급URL : https://stackoverflow.com/questions/12661004/how-to-disable-enable-the-sleep-mode-programmatically-in-ios
'programing' 카테고리의 다른 글
사용자가 Vue 및 Vuex에서 첫 번째 경로에서 두 번째 경로 및 두 번째 경로에서 첫 번째 경로로 이동할 때 첫 번째 경로에서 기능을 실행하려고 합니다. (0) | 2023.06.19 |
---|---|
Python: 외부 루프에서 다음 반복으로 계속 진행 (0) | 2023.06.19 |
CSV 플랫 파일로 데이터를 내보내는 동안 포함된 텍스트 한정자 문제를 해결하는 방법은 무엇입니까? (0) | 2023.06.19 |
판다 데이터 프레임에서 행의 하위 집합 수정 (0) | 2023.06.19 |
원격 풀 중에 모든 태그를 가져오도록 Git 기본값을 설정할 수 있습니까? (0) | 2023.06.19 |