Got Stuck?
Forum for Lovense Developers
Support
Document Feedback

Unity Plugin - iOS SDK

Introduction

This Unity plug-in can be applied to iOS platform for connecting Lovense toys and sending control commands.

Compatibility

Unity version>= 2019.4.0

Api Compatibility Level:

  • For .Net 4.x, the import package name is iOSPlugin_.Net4.x.unitypackage.
  • For .Net Framework, the import package name is iOSPlugin_.NetFramework.unitypackage.
  • For .Net Standard 2.0, the import package name isiOSPlugin_.NetStandard2.0.unitypackage.
  • For .Net Standard 2.1, the import package name is iOSPlugin_.NetStandard2.1.unitypackage.

Import the plugin

  1. Download the plugin package from here. The latest version of the current plugin is V1.2 click to view version records

    iOSPlugin_.Net4.x.unitypackage

    iOSPlugin_.NetFramework.unitypackage

    iOSPlugin_.NetStandard2.0.unitypackage

    iOSPlugin_.NetStandard2.1.unitypackage

  2. Import the appropriate package based on your project's Api Compatibility Level.

    image

  3. Select all options and click import.

    image

  4. After importing, you need to click Tools ->LovenseiOSDevelopment on the toolbar, enter the developer token, click "Save"

    imageimage

  5. The file Assets/StreamingAssets/LovenseToySupportConfig.json is the configuration file for the toy support directive, and the version field represents the version of the information. The current latest version is 1.3. If it is older than this version, it is recommended to download and replace the file.

Dowload: LovenseToySupportConfig.json

The LovenseDemo folder is an example that you can refer to. Removing it won't affect the functionality.

You need to add NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription to the xcode project yourself.

Guide

1. Search toys.

public class YourLovenseToyUI: MonoBehaviour {
	 // do search
   private void DoSearch() {
      LovenseiOSSDK.GetInstance().SearchToys();
   }

   //call back Function,parames is LovenseiOSToy
    private void OnGetToysEvent(LovenseiOSToy newToy){
        //do something when get a new toy 
    }
  

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSGetToysEvent.AddListener(OnGetToysEvent);
   }

    void OnDestory() {
	// Remove listener
	LovenseiOSSDK.oniOSGetToysEvent.RemoveListener(OnGetToysEvent);
    }
}

2. Stop searching for toys

public class YourLovenseToyUI: MonoBehaviour {
	 // do stop search
   private void Dostop() {
      LovenseiOSSDK.GetInstance().StopSearch();
   }
}

3. Connect or DisConnect Toys

public class YourLovenseToyUI: MonoBehaviour {
	 // do connect
   private void Connect(List<string> toyIds) {
      LovenseiOSSDK.GetInstance().ConnectToys(toyIds)();
   }
    //do disconnect
    private void DisConnect(List<string>  toyIds) {
      LovenseiOSSDK.GetInstance().DisConnectToys(toyIds)();
   }

   //call back function,
    private void OnToysConnectEvent(string toyId, int status, string msg){
        //do something
    }
  

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSConnectEvent.AddListener(OnToysConnectEvent);
   }

    void OnDestory() {
	// Remove listener
	LovenseiOSSDK.oniOSConnectEvent.RemoveListener(OnToysConnectEvent);
    }
}

4. Battery monitoring

public class YourLovenseToyUI: MonoBehaviour {
	
    //do get a toy's battery
    private void GetBattery(string toyId) {
      LovenseiOSSDK.GetInstance().SendFunctionWithoutValue(toyId,LovenseCommandType.GET_BATTERY );
   }

   //call back Function,parameters type is (string,int) 
    private void onCallBackBatteryListenerFunc(string toyId, int battery){
    //do something
    } 
  

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSGetBatteryEvent.AddListener(onCallBackBatteryListenerFunc);
   }

    void OnDestory() {
	// Remove listener
	LovenseiOSSDK.oniOSGetBatteryEvent.RemoveListener(onCallBackBatteryListenerFunc);
    }
}

5. Obtain parameters such as device type

public class YourLovenseToyUI: MonoBehaviour {
	
    //do obtain parameters 
    private void GetToyType(string toyId) {
      LovenseiOSSDK.GetInstance().SendFunctionWithoutValue(toyId,LovenseCommandType.GET_DEVICETYPE );
   }
    //callback function,parameters type is (string,string)
   public void onCallBackDeviceTypListenerFunc(string toyId, string type){
        
    }
  

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSGetTypeEvent.AddListener(onCallBackDeviceTypListenerFunc);
   }

    void OnDestory() {
	// Remove listener
	 LovenseiOSSDK.oniOSGetTypeEvent.RemoveListener(onCallBackDeviceTypListenerFunc);
    }
}

6. Send functions commands

public class YourLovenseToyUI: MonoBehaviour {
	
    //do obtain parameters 
   private void SendFunctions(List<string> toyIds, List<LovenseCommand> commands, float timeSec, float loopRunningSec, float loopPauseSec) {
      LovenseiOSSDK.GetInstance().SendFunctions(toyIds, commands, timeSec, loopRunningSec, loopPauseSec);
   }

    //callback function
   private void OnToysCommandEvent(string toyId, int status, string msg){
        
   }

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
   }

    void OnDestory() {
	// Remove listener
    LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
    }
}

7. Send patterns commands

public class YourLovenseToyUI: MonoBehaviour {
	
    //do 
   private void SendPattern(List<string> toyIds, List<LovenseCommandType> typeList, List<int> strengthValues, float timeSec, int intervalsMs) {
      LovenseiOSSDK.GetInstance().SendPattern(toyIds, typeList, strengthValues, timeSec, intervalsMs);
   }

    //callback function,
   private void OnToysCommandEvent(string toyId, int status, string msg){
        
   }

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
   }

    void OnDestory() {
	// Remove listener
    LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
    }
}

8. Send preset commands

public class YourLovenseToyUI: MonoBehaviour {
	
    //do obtain parameters 
   private void List<string> toyIds, int mode, float timeSec) {
      LovenseiOSSDK.GetInstance().SendPreset(toyId, mode, timeSec)}

    //callback function,
   private void OnToysCommandEvent(string toyId, int status, string msg){
        
   }

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
   }

    void OnDestory() {
	// Remove listener
    LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
    }
}

9. Stop toys

  //do 
   private void StopToys(List<string> toyIds) {
      LovenseiOSSDK.GetInstance().StopAll(toyIds)}

    //callback function,
   private void OnToysCommandEvent(string toyId, int status, string msg){
        
   }

   void Awake(){
        // Add listener
    	LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
   }

    void OnDestory() {
	// Remove listener
    LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
    }

Interface

LovenseiOSSDK

Method

GetInstance
SearchToys
  • Description:

    Search for the toys, when a toy is discovered, the oniOSGetToysEvent event will be triggered.

  • Parameters: None

  • Return: None

ConnectToys
  • Description:

    Connect the toys, when a toy's Connection status is changed, the oniOSConnectEvent event will be triggered.???

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdsList<string>yesThe toys you want to connect
  • Return: None

SendFunctions
  • Description:

    Send Function commands to the toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdsList<string>yesThe toys you want to control
    commandsList<LovenseCommand>yesSee LovenseCommand
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length.
    loopRunningSecfloat0notime running for each command loop in second
    loopPauseSecfloat0notime gap for each command loop in second
  • Return: None

SendPattern
  • Description:

    Send a series of Functions to the toys, they will execute all the Functions in types according to the order of the level in values with the interval of intervalsMs.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdsList<string>yesThe toys you want to control
    typesList<LovenseCommandType>yesSee LovenseCommandType
    strengthValuesList<int>yesThe order of the levels
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length.
    intervalsMsint150noThe level interval in milliseconds, should be greater than 100, default 150
  • Return: None

SendPreset
  • Description:

    Send a preset command to the toys.

  • Parameters:

    NameTypeDefaultRequiredDescription
    toyIdsList<string>yesThe toys you want to control
    modeintyesThe preset name to send, we provide four preset patterns : 0:earthquake,1:fireworks,2:pulse,3:wave
    timeSecfloatyesThe total runtime in second, "0" = indefinite time length
  • Return: None

StopAll
  • Description:

    Stop Toy's action.

  • Parameters:

    NameTypeDescription
    toyIdsList<string>The toys you want to stop
  • Return: None

GetSupportCommandsByType(string type)
  • Description:

    Obtain Command types supported by toys through their types

  • Parameters:

    NameTypeDescription
    typestringthe type of toy
  • Return: List<LovenseCommandType>

Event

oniOSGetToysEvent
  • Description:

    Triggered when the toys is discovered.

  • Callback Parameters:

    NameTypeDescription
    newToyLovenseiOSToyThe new toy which is recently discovered
oniOSGetBatteryEvent
  • Description:

    Triggered when a toy's battery is obtained.

  • Callback Parameters:

    NameTypeDescription
    toyIdstringThe toy's id
    batteryintbattery
oniOSGetTypeEvent
  • Description:

    Triggered when a toy's type is obtained.

  • Callback Parameters:

    NameTypeDescription
    toyIdstringThe toy's id
    typestringThe toy's type
oniOSConnectEvent
  • Description:

    Triggered when the toy's connection status has changed.

  • Callback Parameters:

    NameTypeDescription
    toyIdstringThe toy's id
    statusintThe toy's connection status,If equals to 1, it represents successful connection status, while others represent not connected
    msgstringprompt for not currently connected
oniOSCommandEvent
  • Description:

    Triggered when sending commands is complete.

  • Callback Parameters:

    NameTypeDescription
    toyIdstringThe toy's id
    statusintIf equal to 1, it represents successful execution, while others represent unsuccessful execution
    msgstringprompt for not executed

LovenseiOSToy

  • Description:

    The connection information and status of the Toy

  • Properties:

    NameTypeDescription
    nameboolThe name of the toy
    identifierstringThe identifier of the toy
    typeintThe type of the toy
    versionintThe version of the toy
    isConnectedboolThe connection status of the toy
    rssiintThe rssi of the toy
    batteryintThe battery of the toy

LovenseCommand

  • Description:

    The toy control command

  • Properties:

    NameTypeDescription
    typeLovenseCommandTypeSee below
    valueintFunction level

Function Level:

TypeRange
VIBRATE0 - 20
VIBRATE10 - 20
VIBRATE20 - 20
VIBRATE30 - 20
ROTATE0 - 20
PUMP0 - 3
FINGERING0 - 20
DEPTH0 - 3
THRUSTRING0 - 20
GET_DEVICETYPE
GET_BATTERY

LovenseCommandType

  • Description:

    The enum of the toy function type.

  • Enum:

    Value
    VIBRATE
    VIBRATE1
    VIBRATE2
    VIBRATE3
    ROTATE
    PUMP
    THRUSTRING
    FINGERING
    DEPTH
    GET_DEVICETYPE
    GET_BATTERY

The DEPTH command is a setting command that requires the THRUSTRING command to take effect.

Version Records

[Version1.2] - 2023-11-15

  • 1.Add Vibrate3 and Depth commands.

  • 2.Command sending optimization.

  • 3.Update the configuration file to version1.3.

[Version1.1] - 2023-09-12

  • 1.Add a function that can query toy support instructions

  • 2.Change type of 'strengthValues' int[] to List<int> in pattern function

  • 3.Change time type int to float.

[Version1.0] - 2023-08-20

  • 1.Functions

  • 2.Pattern

  • 3.Preset

  • 4.Connect/DisConnect

  • 5.Type/Battery