螢幕鎖
狀態列舉
public enum HMIAccessControl: UInt32 {
/// 鎖定狀態。
case lock = 0
/// 解鎖狀態。
case unlock
/// 不可使用狀態。(嘗試密碼超過限制次數)
case disable
/// 未知。(通常用於數據流的初始預設值)
case unknown
}監聽狀態
FarmLandBikeKit.sleipnir.screenLockPublisher
.sink(receiveCompletion: { completion in
}, receiveValue: { (errorCount, state) in
// 取得 `嘗試密碼錯誤次數` 與 `螢幕鎖狀態` 。
})
.store(in: &self.subscriptions)其實也可以從 裝置資訊 的 screen_lock_error_count 與 screen_lock_state 分別取得數值,不一定要透過 screenLockPublisher 實現。
設定螢幕狀態
鎖定
do {
try FarmLandBikeKit.sleipnir.setScreenAccessControl(.lock)
} catch {
// 執行指令時,發生的例外。
}解鎖
do {
try FarmLandBikeKit.sleipnir.setScreenAccessControl(.unlock(<#password#>))
} catch {
// 執行指令時,發生的例外。
}存取密碼
在 非解鎖狀態 下執行密碼的存取,則會捕獲例外 FarmLandBikeKit.Error.deviceNotUnlocked 。
FarmLandBikeKit.sleipnir.getHmiPasswordCode()
.sink(receiveCompletion: { completion in
}, receiveValue: { codes in
// 取得密碼。
})
.store(in: &self.subscriptions)
FarmLandBikeKit.sleipnir.setHmiPasswordCode(<#T##passwords: [Int]##[Int]#>)
.sink(receiveCompletion: { completion in
}, receiveValue: { codes in
// 設定密碼。
})
.store(in: &self.subscriptions)更改嘗試密碼錯誤上限次數
在 非解鎖狀態 下,若修改上限次數,則會捕獲例外 FarmLandBikeKit.Error.deviceNotUnlocked。
FarmLandBikeKit.sleipnir.setHmiErrorLimit(<#T##limitation: Int##Int#>)
.sink(receiveCompletion: { completion in
}, receiveValue: { state in
// 設定 `嘗試密碼錯誤上限次數` 。
})
.store(in: &self.subscriptions)重置狀態
在 非解鎖狀態 下,若進行設置螢幕鎖 Token ,則會捕獲例外 FarmLandBikeKit.Error.deviceNotUnlocked。
FarmLandBikeKit.sleipnir.setScreenLockToken(<#T##token: UUID##UUID#>)
.sink(receiveCompletion: { completion in
}, receiveValue: { isSuccess in
// 取得重置指令的執行結果。
})
.store(in: &self.subscriptions)- 超過嘗試密碼錯誤達到上限次數,螢幕鎖狀態為
Disable (不可使用狀態)時,可呼叫此方法,重置錯誤次數,並將密碼回復預設值。 - 當帶入的 Token 與電控系統所保存之 Token 不相符,則會捕獲例外
FarmLandBikeKit.Error.screenLockTokenIsNotAllowed。 - 當電控系統尚未保存過任何 Token,此時呼叫此方法,則會捕獲例外
FarmLandBikeKit.Error.screenLockTokenCorrupted。
FarmLandBikeKit.sleipnir.resetScreenAccessControl(<#T##token: UUID##UUID#>)
.sink(receiveCompletion: { completion in
}, receiveValue: { _ in
// 任務執行完畢。
})
.store(in: &self.subscriptions)檢查 Token 是否有效
FarmLandBikeKit.sleipnir.checkScreenLockTokenIsValid()
.sink(receiveCompletion: { completion in
}, receiveValue: { isValid in
// 檢查螢幕鎖 Token 是否有效。
})
.store(in: &self.subscriptions)