iOS HMLink
Link is a representation of a connection between a device and a vehicle.
It enables sending commands to vehicles as well as receiving them through it's delegate. Furthermore, it handles the connection flow and authentication protocols required by HMKit.
Note that it's only allowed to send one command at a time. Queueing of several commands in a sequence has to be done on the application level.
Finally, an HMLink is not initialised by the developer, but received through the HMLocalDevice's delegate.
Instance Methods
Disconnect the connection of the HMLink
Declaration
func disconnect()
Example
import HMKit
/*
HMLink-object received through HMLocalDevice's delegate beforehand
*/
link.disconnect()
Send a command to the HMLink
Declaration
send<C>(command: C, contentType: HMContainerContentType = .autoAPI, requestID: [UInt8] = [], completion: @escaping HMLinkCommandCompletionBlock) throws where C : Collection, C.Element == UInt8
Parameters
command | (UInt8 Collection) binary of the command to send |
contentType | (HMContainerContentType) Type of data sent as content - defaults to .autoAPI |
requestID | ([UInt8]) ID to keep track of a specific command (response will contain the same ID) |
completion | (HMLinkCommandCompletionBlock) Block that gets called when this command is done |
Discussion
The command is encrypted and stored inside a tamper-proof secure container.
Read More
Example
import AutoAPI
import HMKit
/*
HMLink-object received through HMLocalDevice's delegate beforehand
*/
link.send(command: AAWakeUp.wakeUp()) { result in
switch result {
case .failure(let error):
// Handle the error
print(error)
case .success:
// BT "response" is returned through the HMLinkDelegate
break
}
}
Send the revoke command to the HMLink
Declaration
func sendRevoke() throws
Discussion
Revoke is used to remove the certificates for 'this' device from the connected one.
After the revoke is received by the connected device, it deletes the certificates and disconnects.
As it's last act it might send back some data with the completion of the revoke.
Read More
Example
import HMKit
/*
HMLink-object received through HMLocalDevice's delegate beforehand
*/
try link.sendRevoke()
Properties
.certificate?
.delegate?
.state?
Types
HMLinkCommandCompletionBlock
Declaration
typealias HMLinkCommandCompletionBlock = (Result<Void, HMLinkError>) -> Void
Discussion
HMLinkCommandCompletionBlock is a typealias for Result
that gets called when a command succeeds or fails.
Read More
Conforming
Equatable
Declaration
protocol Equatable
Discussion
A type that can be compared for value equality.