iOS SDK
The Lovense iOS SDK is a set of application interfaces based on iOS 13.0 and above. Use this SDK to develop applications for iOS mobile devices. By calling the Lovense SDK interface, you can easily control Lovense toys and build applications with rich functions and strong interactivity.
Note
The Lovense iOS SDK now is not support Objective-C, only support Swift. If you need to use Objective-C, you can mix or use the old version.
Step 1: Get your developer token
Go to the developer dashboard and get your developer token.
Step 2: Download and extract the Lovense SDK
Step 3: Include the SDK in your project
Copy the following files to your project main directory.
Add the required framework LovenseKit.xcframework
to your project.
Configure environment:
TARGETS -> General -> Deployment Info -> Deployment Target -> setting 13.0 or above.
TARGETS -> Info -> add key "Required background modes" with item value "bluetooth-central"
Step 4: Connect Lovense toys and send commands
// Import Lovense
import LovenseKit
// Pass your token into Lovense framework
Lovense.shared.setDeveloperToken("token")
//Add a scan success notification
NotificationCenter.default.addObserver(self, selector: #selector(scanSuccessCallback),
name: .toyScanSuccess, object: nil)
//Scanning toy success notification
@objc func scanSuccessCallback(nofi : Notification)
{
let dict = nofi.object as? [String: LovenseToy]
let scanToyArr = dict?["scanToyArray"]
}
//Add a connect success notification
NotificationCenter.default.addObserver(self, selector: #selector(connectSuccessCallback),
name: .toyConnectSuccess, object: nil)
//Connected toy successfully notification
@objc func connectSuccessCallback(nofi : Notification)
{
let dict = nofi.object as? [LovenseToy]
let toy = dict?["toy"]
}
// Search the toys over Bluetooth
Lovense.shared.searchToys()
//Save the toys
Lovense.shared.saveToys(toys)
// Retrieve the saved toys
Lovense.shared.listToys()
// Connect the toy
Lovense.shared.connectToy("toyId")
// Disconnect the toy
Lovense.shared.disconnectToy("toyId")
// Send a command to the toy
Lovense.shared.sendCommand("ToyId",
command: .vibrate,
parameters: [kSendCommandParamKey_VibrateLevel:20])
Command list
Command | Description |
---|---|
LovenseCommandType.Vibrate | Vibrate the toy. The parameter must be between 0 and 20. |
LovenseCommandType.rotate | Rotate the toy. The parameter must be between 0 and 20. |
LovenseCommandType.rotateClockwise | Rotate clockwise. The parameter must be between 0 and 20. |
LovenseCommandType.rotateAntiClockwise | Rotate anti-clockwise. The parameter must be between 0 and 20. |
LovenseCommandType.rotateChange | Change the rotation direction |
LovenseCommandType.airIn | Airbag inflation for n seconds. The parameter must be between 1 and 3. |
LovenseCommandType.airOut | Airbag deflation for n seconds. The parameter must be between 1 and 3. |
LovenseCommandType.airAuto | Cycle airbag inflation for n seconds and air deflation for n seconds. The parameter must be between 0 and 3 (0 means stop). |
LovenseCommandType.vibrate1 | Activate the first vibrator at level n. The parameter must be between 0 and 20. |
LovenseCommandType.vibrate2 | Activate the second vibrator at level n. The parameter must be between 0 and 20. |
LovenseCommandType.vibrateFlash | Vibrate the toy at level n and flash the light at the same time. |
LovenseCommandType.flash | Flash the light 3 times |
LovenseCommandType.lightOff | Turn off the light (saved permanently). |
LovenseCommandType.lightOn | Turn on the light (saved permanently). |
LovenseCommandType.getLightStatus | Get the light's status (1: on, 0: off) |
LovenseCommandType.alightOff | Turn off Domi/Domi 2 light (saved permanently) |
LovenseCommandType.alightOn | Turn on the Domi/Domi 2 light (saved permanently) |
LovenseCommandType.getAlightStatus | Get the Domi/Domi 2 light status (1: on, 0: off) |
LovenseCommandType.getBattery | Get battery level and working status status |
LovenseCommandType.getDeviceType | Get device/toy information |
LovenseCommandType.startMove | Start tracking the toy movement (0-4) |
LovenseCommandType.stopMove | Stop tracking the toy movement |
LovenseCommandType.preset | Vibrate with a preset pattern. Patterns range from 1 to 10. n=0 will stop vibrations. |
LovenseCommandType.flexerVibrate | Control the vibration of Flexer. The parameter must be between 0 and 20. |
LovenseCommandType.flexerFinger | Control the fingering motion of Flexer. The parameter must be between 0 and 20. |
LovenseCommandType.vibrate3 | Activate the third vibrator at level n. The parameter must be between 0 and 20. |
LovenseCommandType.thrust | Thrust the toy. The parameter must be between 0 and 20. |
LovenseCommandType.multiply | Control three vibrators with different strength level for Lapis. Level range is 0 - 20, set level to -1 for remaining strength level from previous function. |
LovenseCommandType.getTouchMode | Get current mode. The result will be one of [0, 1, 2, 3, 5] |
LovenseCommandType.setTouchMode | Set current mode. The parameter must be one of [0, 1, 2, 3, 5] |
LovenseCommandType.getTouchValue | Get touch attenuation value. will return all level value |
LovenseCommandType.setTouchValue | Set touch attenuation value. The parameter level must be between 1 and 3, attenuation value must be between 0 and 100. |
LovenseCommandType.getTouchLevel | Get touch attenuation level. The result will be between 1 and 3. |
LovenseCommandType.setTouchLevel | Set touch attenuation level. The parameter must be between 1 and 3. |
LovenseCommandType.lvs | set spped & start & end |
LovenseCommandType.getSite | get position |
LovenseCommandType.setSite | set position |
LovenseCommandType.startFeedback | start tracking the toy movement |
LovenseCommandType.endFeedback | stop tracking the toy movement |
LovenseCommandType.getAutoSwitch | get auto switch value |
LovenseCommandType.setAutoSwitch | set auto switch value |
Callback list
Callback | Description |
---|---|
kToyScanSuccessNotification | Found toys |
kToyConnectSuccessNotification | Toy connected |
kToyConnectFailNotification | Failed to connect a toy |
kToyConnectBreakNotification | Toy disconnection |
kToySendCommandErrorNotification | Unknown command received |
kToyCallbackNotificationBattery | Battery status |
kToyCallbackNotificationDeviceType | Device information |
kToyCallbackNotificationGetLightStatus | Light indicator |
kToyCallbackNotificationGetAidLightStatus | Domi/Domi 2 light indicator |
kToyCallbackNotificationListenMove | Toy movement updates |
kToyCallbackNotificationTouchMode | Touch mode updates |
kToyCallbackNotificationTouchValue | Touch value updates |
kToyCallbackNotificationTouchLevel | Touch level updates |
kToyCallbackNotificationTouchInteractive | Interactive data updates |
kToyCallbackNotificationGetSite | site value |
kToyCallbackNotificationSetSite | site value |
kToyCallbackNotificationGetAutoSwitch | auto switch value |
kToyCommandCallbackNotificationAtSuccess | Successful command |
kToyCommandCallbackNotificationAtError | Command exc error |
ErrorCode list
Name | Code | Description |
---|---|---|
LovenseError.illegalCommand | 901 | Illegal command |
LovenseError.loseAuthorized | 902 | Lose authorization |
LovenseError.loseToy | 903 | Lose toy |
LovenseError.losePincode | 904 | Lose PIN code |
LovenseError.commandExecutionFailure | 905 | Command execution failure |
Sync to Lovense patterns
After completing the Native SDK integration, you can easily build features that enable users to sync Lovense toys with media by utilizing the Pattern Playback methods. Support iOS 8.0 and above.
Step 1: Initialization
Initialize the pattern player. Call this method every time you start to use the pattern syncing feature.
Note: This method only needs to be called once during the whole process.
Parameters | Description | Type | Required |
---|---|---|---|
toyIds | The list of connected toys’ id. | NSArray | Required |
pf | Your platform’s name. Contact us if you aren’t sure about this. | NSString | Required |
Lovense.shared.setupPatternPlayer(toyIds: [toyIds], pf: "your platform")
Step 2: Load Pattern
Load the pattern of the media to be played. Call this method every time you start to use the pattern syncing feature or when there is a change in the toy list.
Parameters | Description | Type | Required |
---|---|---|---|
mediaID | The media’s ID from your platform. | NSArray | Required |
public enum PatternPrepareState {
case downloading
case downloadCompleted
case downloadFail
}
public func prepareForPattern(mediaId: String, completion: (@MainActor (PatternPrepareState) -> Void)? = nil)
Example
Lovense.shared.prepareForPattern(mediaId: "Your mediaId") { [weak self] state in
guard let self else { return }
switch state {
case .downloading:
// ...
break
case .downloadCompleted:
// play pattern
Lovense.shared.playPattern(currentTime: self.currentTime() * 1000)
case .downloadFail:
// ...
break
@unknown default: break
}
}
Step 3: Play Pattern
Parameters | Description | Type | Required |
---|---|---|---|
currentTime | The playing time duration so far. The default is 0. (in ms) | NSTimeInterval | Optional |
totalTime | The total time of media. (in ms) | NSTimeInterval | Required |
Lovense.shared.playPattern(currentTime: 0)
Step 4: Sync with Media
If the rate or progress changes while playing the media, call the following methods to re-sync the rate and time.
Parameters | Description | Type | Required |
---|---|---|---|
rate | The playback rate. The default is 1.0. | CGFloat | Optional |
Lovense.shared.setRate(1.0)
Parameters | Description | Type | Required |
---|---|---|---|
currentTime | The playing time duration so far. (in ms) | NSTimeInterval | Required |
Lovense.shared.syncCurrentTime(20000)
Pause the pattern when the media is paused or loading, so the toy’s reaction matches the media content.
Lovense.shared.pausePattern()
Calling this method will pause the playing and reset the time to 0.
Lovense.shared.stopPattern()