# \*iOS - ELM API

**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 accesories\
Acts as a Bluetooth LE accessory

**When initialisingRaxelPulse SDK library, be sure to call:**\
\
\[\[RPCPermissionsWizard returnInstance] setupBluetoothEnabled];\
\[RPEntry enableELM: YES];

#### Search ELM Devices

```
[[RPELMEntry instance] getELMDevicesWithCompletion:^(id  _Nullable response, NSArray * _Nullable errors) {
    for(RPELMItem *item in response) {
        NSLog(@"item.tag = %@ item.uuid = %@", item.name, item.uuid);
    }
}];
```

#### Get Vehicles

```
[[RPELMEntry instance] getVehicles:^(id  _Nullable response, NSArray * _Nullable errors) {
    NSLog(@"%@",response);
}];
```

#### Connect ELM with Vehicle

```
[[RPELMEntry instance] connectDevice:@"92D29DC3-48C0-D6A6-3700-4264BEEB4762" vehicleToken:@"28e4f4ea-b495-40ec-875b-17b48c39bc07" withCompletion:^(BOOL response, NSArray * _Nullable errors) {
    if (response) {
        // Success
    } else {
        for error in errors {
            NSLog(@"error - %@", [error localizedDescription])
    }
}];
```

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.\<YOURAPPNAME>.elm"). The example code is shown below.

```
RPELMEntry.instance().connectDevice(@"92D29DC3-48C0-D6A6-3700-4264BEEB4762", vehicleToken: ct!, 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
                }
            }
    })
```

```
public extension DispatchQueue {
    
    private static var _onceTracker = [String]()
    
    class func once(token: String, block:()->Void) {
        objc_sync_enter(self); defer { objc_sync_exit(self) }
        
        if _onceTracker.contains(token) {
            return
        }
        
        _onceTracker.append(token)
        block()
    }
}
```

At any time you can request the status of the connection to ELM (connected/not connected) and the timestamp date of the last connection.

```
let isConnect = RPELMEntry.instance().getLastSession().isConnect
let lastConnect = RPELMEntry.instance().getLastSession().lastConnect
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-old.telematicssdk.com/sdk-features/bluetooth-obd/elm-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
