Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
parvez-geokey opened this issue Sep 2, 2024 · 1 comment

Comments

@parvez-geokey
Copy link

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?
  • Do we need to use any additional API along with the TTLock.getLockTime and TTLock.setLockTimeWithTimestamp methods?
  • Could you provide a step-by-step guide to properly implement this feature?
  1. Clarification on Methods:
  • TTLock.getLockTime: How exactly does this method work?
  • TTLock.setLockTimeWithTimestamp: What should we consider while using this method?
  • TTLock.getLightTime and TTLock.setLightTime: What is the purpose of these methods, and how should they be implemented?
  1. Daylight Saving Setting:
  • We have not yet implemented the "Daylight saving setting" feature as we're unsure of its exact purpose and usage.
  • Could you please explain what this feature does and provide a step-by-step guide to implementing it using the TTLock SDK?

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
Copy link
Owner

ttlock commented Sep 3, 2024

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 ?? "")
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants