1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- //
- // BLEConnectUtils.swift
- // SolarBT
- //
- // Created by weclouds on 2019/11/4.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- class BLEConnectUtils: NSObject {
-
- static let shared : BLEConnectUtils = {
- let tool = BLEConnectUtils()
- return tool
- }()
-
- var startWrite:(()->Void)?
-
- private var timer: DispatchSourceTimer?
-
- //查询是否可写
- func checkWriteStatus(_ startWrite : @escaping (()->Void)) {
- self.startWrite = startWrite
- timer = DispatchSource.makeTimerSource(flags: [], queue: DispatchQueue.global())
- //dealiyne 开始执行时间
- //repeating : 重复时间将
- //leewa : 时间精度
- timer?.schedule(deadline: .now() + .seconds(0), repeating: DispatchTimeInterval.seconds(1), leeway: DispatchTimeInterval.seconds(0))
- timer?.setEventHandler(handler: {
- self.timerAction()
- })
- timer?.resume()
-
- }
-
- @objc func timerAction() {
- let canWrite = BabyBluetoothSwift.shareInstance()?.canWrite()
-
- log.debug( "是否能写 -- \(canWrite)")
- if BabyBluetoothSwift.shareInstance()?.canWrite() == true {
- self.startWrite!()
- timer?.cancel()
- timer = nil
-
- }
- }
-
-
- }
|