> For the complete documentation index, see [llms.txt](https://cavedu.gitbook.io/linkit-7697/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cavedu.gitbook.io/linkit-7697/linkit-7697-arduinoide/kai-fa-zhi-nan/shi-yong-ble-di-gong-hao-lan-ya/lble-api-zhi-nan/lbleservice.md).

# LBLEService

此類別代表一個 BLE 周邊裝置當中的 GATT 服務（Service），負責儲存該服務相對應的各種資訊。開發者應該將該服務所需要的資料特性（characteristic）都透過 **addAttribute**() 來添加到此服務的物件之中。

底層的 BLE 藍牙框架會在背景不斷存取此類別的物件中的內容，所以，應該將此物件宣告於全域範圍，以確保此物件的生命週期夠長。

### Constructor <a href="#lbleservice-constructor" id="lbleservice-constructor"></a>

&#x20;LBLEService ()

{% tabs %}
{% tab title=" LBLEService ()" %}
建構一個 GATT 服務物件。

**Syntax**

**Parameters**

UUID: 想要創建的服務的 UUID。

**Returns**

LBLEService instance.
{% endtab %}
{% endtabs %}

### Methods <a href="#lbleservice-methods" id="lbleservice-methods"></a>

&#x20;addAttribute()

{% tabs %}
{% tab title=" addAttribute()" %}
添加一個 **LBLECharacteristic** 資料特性（characteristic）物件到此服務當中。

**Syntax**

**Parameters**

characteristic: 想要插入至此服務的資料特性（characteristic）。請注意，插入到此服務的資料特性物件只是被參照，而不是被複製，所以開發者需要確保資料特性的物件不會後續被摧毀。（也就是說，請將該資料特性物件宣告為全域變數）。

**Returns**

none
{% endtab %}
{% endtabs %}
