# Unity iOS SDK Plugin

**URL:** <https://forum.developer.lovense.com/t/unity-ios-sdk-plugin/71>\
**Category:** Unity\
**Created:** [July 19, 2023, 8:33am UTC](https://forum.developer.lovense.com/t/unity-ios-sdk-plugin/71 "2023-07-19T08:33:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trebor](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Trebor](https://forum.developer.lovense.com/u/Trebor)\
**Post date:** [July 19, 2023, 8:33am UTC](https://forum.developer.lovense.com/t/unity-ios-sdk-plugin/71/1 "2023-07-19T08:33:56Z")

</div>

**Description:**

This Unity plug-in can be applied to the iOS platform to realize the function of connecting Lovense toys and sending control commands.

**Compatibility:**

Unity version \> 2018.4.0

Scripting Backend: Mono

Api Compatibility Level: \*For .Net 4.x the import name is “\*\_Net4.x\*.unitypackage”.

Api Compatibility Level: \*For .NetFramework the imported package name is “\*.NetFramework\*.unitypackage”.

Api Compatibility Level: \*For .NetStandard2.1 the imported package name is “\*.NetStandard2.1\*.unitypackage”

Api Compatibility Level: \*For .NetStandard2.0 the imported package name is “\*.NetStandard2.0\*.unitypackage”

**Steps to integrate the plugin:**

1. Import the appropriate package based on your project’s Api Compatibility Level\*.  

2. Select all options and click import.  

3. After successfully importing the plugin, a new Tools-\>LovenseAndroidDeveloper menu item will be added to the Unity menu bar. Click to enter and set the developer token, then click Save to save the token.  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/lovense2/original/1X/96f6bda3c3a9d21f8cc6d71d95213143dc5a39f9.png)

**At this point, you can quickly start developing using the iOS SDK. The LovenseDemo folder is an example, and deleting it does not affect your project.**

**Guide:**

**1. Search toys**

> Add listener: LovenseiOSSDK.oniOSGetToysEvent.AddListener(OnGetToysEvent);

> Remove listener: LovenseiOSSDK.oniOSGetToysEvent.RemoveListener(OnGetToysEvent);

The callback function is not allowed to take parameters, and the obtained toys are all in LovenseiOSSDK.iOSToys

> Search toys: LovenseiOSSDK.GetInstance().SearchToys();

**2. Stop searching for toys**

> LovenseiOSSDK.GetInstance().StopSearch();

**3. Connect Toys**

> Add listener: LovenseiOSSDK.oniOSConnectEvent.AddListener(onToysConnectEvent);
> 
> Remove listener: LovenseiOSSDK.oniOSConnectEvent.RemoveListener(onToysConnectEvent);
> 
> Listening callback function: public void onToysConnectEvent(string toyId, int status, string msg){}
> 
> Connect Toys: LovenseiOSSDK.GetInstance().ConnectToy(toyId);
> 
> Disconnect: LovenseiOSSDK.GetInstance().DisConnectToy(toyId);

**4. Battery monitoring**

Add battery monitoring:

> LovenseiOSSDK.oniOSGetBatteryEvent.AddListener(onCallBackBatteryListenerFunc);

Remove power monitoring:

> LovenseiOSSDK.oniOSGetBatteryEvent.RemoveListener(onCallBackBatteryListenerFunc);

> Listening function: public void onCallBackBatteryListenerFunc(string toyId, int battery)

Send query:

> LovenseiOSSDK.GetInstance().SendFunctionWithoutValue(LovenseCommandType.GET\_BATTERY );

**5. Obtain parameters such as device type**

> LovenseiOSSDK.GetInstance().SendFunctionWithoutValue(toyId, LovenseCommandType.GET\_DEVICETYPE);

**6. Send Functions**

Single Function:

> LovenseiOSSDK.GetInstance().SendFunction(toyId, command, timeSec, loopRunning, loopPause);

> Multiple Functions: LovenseiOSSDK.GetInstance().SendFunctions(toyId, commands, timeSec, loopRunning, loopPause);

> command: the type is LovenseiOSCommand
> 
> commands: the type is List
> 
> timeSec: total running time
> 
> loopRunning: Running time. Use in conjunction with loopPause to control and stop the device.
> 
> loopPause: Suspend time. Use in conjunction with the above loopRunning to control and stop the device.

**7. Send Patterns**

> LovenseiOSSDK.GetInstance().SendPattern(toyId, typeList, valueList, timeMs, timeSec);
> 
> typeList: the type of command, the type is List
> 
> valueList: a list of intensity changes, the type is List
> 
> timeMs: how often to change the intensity, time unit: milliseconds
> 
> timeSec: total running time, time unit: seconds

**8. Send Preset**

> LovenseiOSSDK.GetInstance().SendPreset(toyId, mode, timeSec);

There are currently four presets:

> mode=0 earthquake mode
> 
> mode=1 fireworks mode
> 
> mode=2 pulse mode
> 
> mode=3 wave mode

> timeSec: total running time, time unit: seconds

**9. Stop Toys**

> LovenseiOSSDK.GetInstance().StopAll(toyId);

---

<div class="post-metadata">

**Author:** ![Trebor](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Trebor](https://forum.developer.lovense.com/u/Trebor)\
**Post date:** [July 20, 2023, 3:44am UTC](https://forum.developer.lovense.com/t/unity-ios-sdk-plugin/71/4 "2023-07-20T03:44:30Z")

</div>

# **Download the plugin here:**
 [https://p.lovense.com/Lovense-Unity-Plugin](https://p.lovense.com/Lovense-Unity-Plugin)
