ttlock / iOS_SDK_Demo

TTLock is a global provider of solutions for smart locks. We provide PCBA and softwares for lock manufactures and end users. We provide open API/SDK for developers. With these APIs/SDKs, you can develop your own applications to manage smart locks. The SDK here is for mobile app to communicate with locks via bluetooth.
MIT License
13 stars 12 forks source link

Need Guidance on Implementing "Calibrate Time" and "Daylight Saving Setting" Features Using TTLock SDK #40

Open parvez-geokey opened 2 months ago

parvez-geokey commented 2 months ago

I need detailed guidance on implementing the "Calibrate time" and "Daylight saving setting" features using the TTLock SDK.

Current Implementation: For "Calibrate time," our current approach involves using the TTLock.getLockTime method to retrieve the lock's current time and the TTLock.setLockTimeWithTimestamp method to calibrate the lock time. However, we're uncertain if this is the correct approach, as we have not used any specific API and have noticed a time variation between our app and the TTLock official app.

Please find below code snippets for our current implementation:

//To get lock time
func getLockTime() {
    appLoaderView.startAnimating()
    TTLock.getLockTime(withLockData: lockData) { time in
        appLoaderView.stopAnimating()

        self.labelTime.text = self.convertTimeIntervalToDate(timeInterval: time)
    } failure: { error, message in
        appLoaderView.stopAnimating()
        self.ShowAlert(titleStr: "", message: message ?? "")
    }
}

//To set lock time, we call below method to calibrate time.
func setLockTime() {
    let currentDate = Date()
    let timestamp = Int64(currentDate.timeIntervalSince1970 * 1000)

    appLoaderView.startAnimating()
    TTLock.setLockTimeWithTimestamp(timestamp, lockData: self.lockData) {
        appLoaderView.stopAnimating()
        self.labelTime.text = self.convertTimeIntervalToDate(timeInterval: timestamp)
    } failure: { error, message in
        appLoaderView.stopAnimating()
        self.ShowAlert(titleStr: "", message: message ?? "")
    }
}

//Convert time interval to date
func convertTimeIntervalToDate(timeInterval: Int64) -> String {
    let date = Date(timeIntervalSince1970: TimeInterval(timeInterval) / 1000.0)
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy.MM.dd HH:mm:ss"
    return dateFormatter.string(from: date)
}

Queries:

  1. Is our current implementation for "Calibrate time" correct?
  1. Clarification on Methods:
  1. Daylight Saving Setting:

Reference: I have previously posted an issue regarding the "Daylight saving setting" feature but didn't get a clear idea about its implementation. Here is the link to that issue: Issue #25.

Your assistance with these questions and a detailed implementation guide would be greatly appreciated.

Thank you for your support!

ttlock commented 2 months ago

1 correct, no need other steps 2 TTLock.getLockTime is to connect the lock and read the time of the clock in the lock TTLock.setLockTimeWithTimestamp is nothing to consider TTLock.getLightTime and TTLock.setLightTime belong to the safe lock, used to control the lighting time 3 Daylight Saving Setting: The method given earlier is not easy to understand, use the following method first step: call API : https://euopen.sciener.com/document/doc?urlName=cloud%2Flock%2FchangeTimezoneRawOffsetEn.html , this api will return new "lockData" second step: use the new "lockData" to setLockTime

func setLockTime() { let currentDate = Date() let timestamp = Int64(currentDate.timeIntervalSince1970 * 1000)

appLoaderView.startAnimating()
TTLock.setLockTimeWithTimestamp(timestamp, lockData: new "lockData") {
    appLoaderView.stopAnimating()
    self.labelTime.text = self.convertTimeIntervalToDate(timeInterval: timestamp)
} failure: { error, message in
    appLoaderView.stopAnimating()
    self.ShowAlert(titleStr: "", message: message ?? "")
}

}