Setting up for iOS app
Setting up the environment
-
Add a key to
Info.plist
file of your app with a description of the requirement why they need Bluetooth:Privacy - Bluetooth Peripheral Usage Description
-
In xCode, in the Signing & Capabilities project section, add the following items:
+ Uses Bluetooth LE accessories
+ Acts as a Bluetooth LE accessory -
When initialisingRaxelPulse SDK library, be sure to call:
[[RPCPermissionsWizard returnInstance] setupBluetoothEnabled];
[RPEntry enableELM: YES];
RPPermissionsWizard.returnInstance().setupBluetoothEnabled()
RPEntry.enableELM(true)
Setting up the connection
To set up the connection between SDK and device, please follow the steps below:
1. Search Bluetooth device
[[RPELMEntry instance] getELMDevicesWithCompletion:^(id _Nullable response, NSArray * _Nullable errors) {
for(RPELMItem *item in response) {
NSLog(@"item.tag = %@ item.uuid = %@", item.name, item.uuid);
}
}];
RPELMEntry.instance().getELMDevices{response, errors in
//
}
2. Get a vehicle
if you haven't registered a vehicle yet, please refer to the _Vehicle management
[[RPELMEntry instance] getVehicles:^(id _Nullable response, NSArray * _Nullable errors) {
NSLog(@"%@", response);
}];
RPELMEntry.instance().getVehicles{response, errors in
self.vehiclesArray = response as! NSArray
}
3. Connect Bluetooth OBD to the vehicle (from the step above)
[[RPELMEntry instance] connectDevice:@"UUID_DEVICE_TOKEN" vehicleToken:@"VEHICLE_TOKEN" withCompletion:^(BOOL response, NSArray * _Nullable errors) {
if (response) {
// Success
} else {
NSLog(@"error - %@", [error localizedDescription]);
}
}];
RPELMEntry.instance().connectDevice("UUID_DEVICE_TOKEN", vehicleToken:"VEHICLE_TOKEN", withCompletion: {[weak self] response, errors in
guard let strongSelf = self else {
return
}
if response == true {
print("\(response)")
}
})
Troubleshouting
When connecting to ELM, you may experience difficulties getting a repetitive response in the [RPELMEntry instance] connectDevice method.
We recommend doing DispatchQueue.once (token: "com..elm").Please refer to the code example below in Swift language
[[RPELMEntry instance] connectDevice:@"UUID_DEVICE_TOKEN" vehicleToken:@"VEHICLE_TOKEN" withCompletion:^(BOOL response, NSArray * _Nullable errors) {
if (response) {
// Success
} else {
NSLog(@"Errors %@", errors);
}
}];
RPELMEntry.instance().connectDevice("UUID_DEVICE_TOKEN", vehicleToken: "VEHICLE_TOKEN", withCompletion: {[weak self] response, errors in
guard let strongSelf = self else {
return
}
if let theErrors = errors as? [NSError] {
var isNetwork = false
for item in theErrors {
if item.code == 2005 {
isNetwork = true
break;
}
}
if isNetwork {
//Internet connection error
}
DispatchQueue.main.async {
if response == true {
print("\(response)")
} else {
print("\(response)")
DispatchQueue.once(token: "com.<YOURAPPNAME>.elm") {
//Next connection action
}
}
})
Get connection status
At any time you can request the status of the connection to ELM (connected/not connected) and the timestamp date of the last connection.
Connection status
BOOL isConnect = [[[RPELMEntry instance] getLastSession] isConnect];
let isConnect = RPELMEntry.instance().getLastSession().isConnect
Timestamp date of the last connection.
NSDate *lastConnect = [[[RPELMEntry instance] getLastSession] lastConnect];
let lastConnect = RPELMEntry.instance().getLastSession().lastConnect
Updated almost 3 years ago