iOS SDK
Getting started
Section titled “Getting started”GET SDK
Section titled “GET SDK”This topic describes how to use CocoaPods to quickly integrate the SDK for iOS into your project. The SDK requires iOS 13.0 or later.
Use CocoaPods for fast integration
Section titled “Use CocoaPods for fast integration”-
Update CocoaPods to the latest version. For more information about CocoaPods, see CocoaPods Guides.
-
Add the following code block to the
Podfile:
platform :ios, "13.0"
target "Project_Name" do use_frameworks! pod "RogoCore"end- In the root directory of your project, run
pod install.
Initialize the SDK
Section titled “Initialize the SDK”To using RogoCore Library:
import RogoCoreAuthenticate
Section titled “Authenticate”Setting eviroment
RGCore.shared.setTargetEnviroment(environment: <RGBNetworkEnvironment)Parameter
| Name | Description |
|---|---|
| environment | Depends on getting appkey in dashboard: 1. prod: .production 2. stag: .development |
Config appKey and app Secret
RGCore.shared.config(appKey: String, appSecret: String) { response, error in guard response == true, error == nil else { return } }Parameter
| Name | Description | Source |
|---|---|---|
| appKey | The credential information exclusive to the app. | In the dashboard, open the project, then Apps |
| appSecret | The secret key of the app. | In the dashboard, open the project, then Apps |
Get appKey and appSecet on Dashboard
- Sign in to the dashboard
Dashboard: dashboard.rogo.com.vn
No partner yet? Create one.
-
Select
Project. -
Create
Project.
Choose Add Project > Enter Project Name > OK
Fill infomation for project
| Name | Description |
|---|---|
| Name | The name of Project. |
- Create Application.
Select the project that has been created.
Choose App > Create App
Fill information for application
| Name | Description |
|---|---|
| Name | The name of Application |
| BundleId For IOS | The uniquely identifies an application in Apple’s ecosystem |
| Package Name for Android | Ignore |
| Version | The version of application |
- Select
Apps.
Choose App > Get appKey and appSecret
Demo App
Section titled “Demo App”The demo app in the sample project is used for reference only. Do not use the demo app for commercial purposes.Prepare the demo
Section titled “Prepare the demo”Get appKey and appSecret for iOS.
Make sure that appKey, and appSecret are the ones shown in the dashboard. Any mismatch will cause the SDK development app to fail.
Demo feature
Section titled “Demo feature”The demo app is coded in Swift. You can get the sample on GitHub. The following features are supported:
- User registration and login
- User management
- Home management
- Wi-Fi Easy Connect (EZ) mode and access point (AP) mode
- Device Control
Register And Login With Phone Number
Section titled “Register And Login With Phone Number”the SDK supports multiple types of user accounts, such as mobile phone numbers, email addresses, and username.
Different types of accounts support the following specific capabilities:
- An account that is registered with a mobile phone number supports two login methods: verification code login and password login.
- An account that is registered with an email address also supports two login methods: verification code login and password login.
- An account that is registered with username also supports login method: password login.
SignUp
Section titled “SignUp”RGCore.shared.auth.signUp(email: String, username: String, phone: String, password: String, completion: RGBCompletionObject<RGBAuthResponse>)Parameter
| Name | Description |
|---|---|
| The email | |
| username | The username |
| phone | The mobile phone number |
| password | The password |
| completion | The success callback |
Example
RGCore.shared.auth.signUp(email, username: username, phone: nil, password: password) { response, error in if error == nil { self.state.send(.success) } else { if let rgErrr = error as? RGBError { if rgErrr.errorCode == .username_is_already_existed { self.state.send(.usernameExisted) } else if rgErrr.errorCode == .email_is_already_existed { self.state.send(.emailExisted) } } self.state.send(.fail(error: error)) }Verify Email
Section titled “Verify Email”RGCore.shared.auth.verifyAuthenCode(code: String, completion: RGBCompletionObject<RGBAuthResponse>)Parameter
| Name | Description |
|---|---|
| code | The verify code |
| completion | The success callback |
The SDK supports registration and login with a user’s mobile phone number, email and password.
Check if the user is logged in or not, if yes then do not ask the user to log in again.
if RGCore.shared.auth.isAuthenticated() == false {//not login} else {//Login}Login by username
Section titled “Login by username”RGCore.shared.auth.signInWithUsername(username: String, password: String, completion: RGBCompletionObject<RGBAuthResponse>)| Name | Description |
|---|---|
| username | The username |
| password | The password |
| completion | The success callback |
Login by email
Section titled “Login by email”RGCore.shared.auth.signInWithEmail(email: String, password: String, completion: RGBCompletionObject<RGBAuthResponse>)| Name | Description |
|---|---|
| The user’s email | |
| password | The password |
| completion | The success callback |
Forgot password
Section titled “Forgot password”Send verify code
RGCore.shared.auth.requestVerifyCode(email: String, completion: RGBCompletionObject<RGBAuthResponse>)| Name | Description |
|---|---|
| The user’s email | |
| completion | The success callback |
Verify code
RGCore.shared.auth.resetPasswordWith(code: String, newPassword: String, completion: RGBCompletionObject<RGBAuthResponse>)| Name | Description |
|---|---|
| code | The verify code |
| newPassword | The new password |
| completion | The success callback |
Logout
Section titled “Logout”RGCore.shared.auth.signOut(completion: response: RGBAuthResponse, (any Error)?) -> Void)| Name | Description |
|---|---|
| completion | nil: sign out is success |
Location Management
Section titled “Location Management”Get list Location
Section titled “Get list Location”Get all location in account
RGCore.shared.user.locationsCheck selectedLocation
Section titled “Check selectedLocation”RGCore.shared.user.selectedLocation| Name | Description |
|---|---|
| The user’s email | |
| password | The password |
| completion | nill: success |
Set Location
Section titled “Set Location”RGCore.shared.user.setSelectedLocation(locationId: String)| Name | Description |
|---|---|
| locationId | The location’s ID |
Add location
Section titled “Add location”RGCore.shared.user.createLocation(label: String, desc: String, completion: RGBCompletionObject<RGBLocation?>?)| Name | Description |
|---|---|
| label | The location’s new name |
| desc | The location’s type |
| completion | The success callback |
Modify location
Section titled “Modify location”RGCore.shared.user.updateLocations(id: String, label: String, desc: String, completion: RGBCompletionObject<RGBLocation?>?)| Name | Description |
|---|---|
| id | Location’s uuid |
| label | The location’s new name |
| desc | The location’s type |
| completion | The success callback |
Delete loation
Section titled “Delete loation”RGCore.shared.user.deletedLocations(id: String, completion: RGBCompletionObject<Bool>?)| Name | Description |
|---|---|
| id | Location’s uuid |
| completion | The success callback |
Add Wile Device
Section titled “Add Wile Device”Scan Wile Device
Section titled “Scan Wile Device” RGCore.shared.device.scanAvailableWileDevice(timeout: Int, completion: RGBCompletionObject<RGBMeshScannedDevice?>?)| Name | Description |
|---|---|
| timeout | Set timeout |
| completion | The success callback |
Add Wile device
Section titled “Add Wile device”RGCore.shared.device.startConfigWileDevice(device: RGBMeshScannedDevice, didUpdateProgessing: ((Int) -> ())?, wifiScanCompletedHandler: (([RGBWifiInfo]) -> ())?, wifiSelectionHandler: &((String, String) -> ())?, wifiConnectErrorHandler: ((String?, String?, RGBWifiConnectionErrorType) -> ())?, didCompletedHandler: ((RGBDevice?) -> ()))| Name | Description |
|---|---|
| device | Set timeout |
| didUpdateProgessing | Return completedPercent |
| wifiScanCompletedHandler | Get list RGBWifiInfo |
| wifiSelectionHandler | Get SSID |
| wifiConnectErrorHandler | Notification Wifi error |
| didCompletedHandler | Return device |
Cancel config Wile process
Section titled “Cancel config Wile process”RGCore.shared.device.cancelWileConfig()Add RF Device
Section titled “Add RF Device”Check RF hub device status
Section titled “Check RF hub device status”RGCore.shared.device.getRFHubStatus(at: RGBLocation, observer: AnyObject?, timeout: Int, completion: (_ response: RGBRFHubStatus?, (any Error)?) -> Void)| Name | Description |
|---|---|
| at | The locationID |
| observer | self |
| timeout | Timeout. Unit: seccond |
| completion | Check error |
Scan RF device
Section titled “Scan RF device”RGCore.shared.device.startScanRFDevice(deviceType: RGBProductType, gateWay: RGBDevice, timeout: Int, observer: AnyObject?, completion: <RGBMeshScannedDevice?>?)| Name | Description |
|---|---|
| deviceType | The locationID |
| gateWay | |
| observer | self |
| timeout | Timeout. seccond |
| completion | Check error |
Add RF Device
Section titled “Add RF Device”RGCore.shared.device.addRFDevice(device: RGBMeshScannedDevice, toHub: RGBDevice, didUpdateProgessing: (_ completedPercent: Int) -> (), completion: (_ response: RGBDevice?, (any Error)?) -> Void)| Name | Description |
|---|---|
| deviceType | The locationID |
| gateWay | |
| observer | self |
| timeout | Timeout. seccond |
| completion | Check error |
Example:
RGCore.shared.device.addRFDevice(device: device, toHub: deviceHub) { completedPercent in
// Hiển thị phần trăm lbPercent.text = completedPercent
} completion: { response, error in
if error == nil {
// Thêm thiết bị thành công
}
// Thêm thiết bị thất bại print(error)
}Stop scan RF device
Section titled “Stop scan RF device”RGCore.shared.device.stopScanRFDevice(gateWay: RGBDevice)| Name | Description |
|---|---|
| gateWay | The locationID |
Device Management
Section titled “Device Management”Get list devices in location
Section titled “Get list devices in location”Get all devicein location
RGCore.shared.user.selectedLocation?.allDevicesInLocationGet list devices in groupID
Section titled “Get list devices in groupID”Using filter function
Example:
listDevice = RGCore.shared.user.selectedLocation?.allDevicesInLocation.filter {$0.groupID == selectedGroup.uuid}Classify devices by connection type
Section titled “Classify devices by connection type”for device in listDevice {if device.productType == .BM_DoorSensor or == .Zigbee_Plug or == .IR_AirCondition_Remote }| Name | Description |
|---|---|
| BM | The Bluetooth Mesh device |
| Zigbee | The Zigbee device |
| IR | IR controlled devices such as air conditioners, fans, TVs |
Update device’s name
Section titled “Update device’s name”RGCore.shared.device.updateDevice(deviceId: String, label: String?, elementLabels: [String: String]?, completion: RGBCompletionObject<RGBDevice?>?)| Name | Description |
|---|---|
| deviceID | Device’s uuid |
| label | New name |
| elementLabels | elementID : new name of device |
| completion | check error |
| respone | RGBDevice with new name |
Example
RGCore.shared.device.updateDevice(device.uuid, label: "newName", elementLabels: nil) { response, error in if error == nil { //Success } else { //Fail}Delete device
Section titled “Delete device”RGCore.shared.device.deleteDeviceWith(deviceUUID: String, completion: RGBCompletionObject<RGBDevice?>?)| Name | Description |
|---|---|
| deviceUUID | Device’s uuid |
| completion | check error |
Update group device
Section titled “Update group device”RGCore.shared.device.setGroupForDeviceWith(deviceId: String, groupId: String, completion: RGBCompletionObject<RGBDevice?>?)| Name | Description |
|---|---|
| deviceId | Device’s uuid |
| groupId | The ID of new group |
| completion | check error |
Add device to vitual group
Section titled “Add device to vitual group”RGCore.shared.group.updateGroupMemberElement(elementIds: [Int], ofDeviceWith: String, toGroupdWith: String, observer: AnyObject?, completion: RGBCompletionObject<RGBGroupMember?>?)| Name | Description |
|---|---|
| elementIds | The element’s ID |
| ofDeviceWith | The device’s uuid |
| toGroupdWith | The vitual group’s ID |
| observer | self |
| completion | check error |
Delete device in vitual group
Section titled “Delete device in vitual group”RGCore.shared.group.removeGroupMember(deviceWithUUID: String, fromGroupWith: RGBGroup, observer: AnyObject?, completion: RGBCompletionObject<RGBGroupMember?>?)Device State
Section titled “Device State”Get state
Section titled “Get state”- Subscribe to get state
Get state of single device
RGCore.shared.device.subscribeStateChangeOfDeviceWith(deviceUUID: String, observer: AnyObject?, statusChangedHandler: RGBCompletionObject<RGBDeviceState?>?)| Name | Description |
|---|---|
| deviceUUID | The device’s UUID |
Get state of list device
RGCore.shared.device.subscribeStateChangeOf(devicesUUID: [RGBDevice], observer: AnyObject?, statusChangedHandler: RGBCompletionObject<RGBDeviceState?>?)| Name | Description |
|---|---|
| devices | Array contant uuid devices |
- Get state when device change state
RGCore.shared.device.requestStateOf(device: RGBDevice)Example
RGCore.shared.device.subscribeStateChangeOf(deviceUUID: device, observer: self) {[weak self] res , error in guard let self = self, res != nil, res!.deviceUUID?.uppercased() == device.uuid?.uppercased(), let states = res?.stateValues, states.count > 0 else { return }
self.updateElementWith(states: states)
self.getLog() }- Type Casting
func updateDeviceState(states: [RGBDeviceElementState], cell: ListLightCell ) { for state in states { if let stateValue = state.commandValues.first(where: {$0.type == .ONOFF}) as? RGBValueOnOff {
cell.swOnOff.isOn = stateValue.on == 1 } } }| Name | Description |
|---|---|
| RGBValueOnOff | On/Off |
| RGBValueBrightness | |
| RGBValueKelvin | |
| RGBValueBrightnessKelvin | |
| RGBValueOpenClose | Open/Close |
Example
Get state of Door sensor*
Sate:
- Open/Close
for state in states {
if let currentState = state.commandValues.first(where: {$0.type == .EVENT_DOOR}) as? RGBValueOpenClose { if currentState.open == 1 { //Open } else { //Close } } }Get state of bulb light
State:
- On/off
- Brightness/Kelvin
for state in states { if let stateValue = state.commandValues.first(where: {$0.type == .ONOFF}) as? RGBValueOnOff { swOnOffState.isOn = stateValue.on == 1 } if let stateBrightnessKelvin = state.commandValues.first(where: {$0.type == .BRIGHTNESS_KELVIN}) as? RGBValueBrightnessKelvin { -stateBrightnessKelvin.b <.b là brightness> -stateBrightnessKelvin.k <.k là kelvin> } }Get list device’s log
Section titled “Get list device’s log” RGCore.shared.device.getSensorLogOf(deviceUUID: RGBDevice, dayToGetLog: Date, completion: RGBCompletionObject<RGBDeviceLogResponse?>?)Example
var date = Date()
date = Calendar.current.date(byAdding: .day, value: 0, to: date)!
RGCore.shared.device.getSensorLogOf(deviceUUID: RGBDevice, dayToGetLog: date) { [weak self] response, error in
// Get list log of device:
let logs = response?.deviceLogParts.flatMap({$0.logs}), self.listLogs = logs
}| Name | Description |
|---|---|
| deviceUUID | The UUID of device |
| date | Period time |
Get list group in location
Section titled “Get list group in location”RGCore.shared.user.selectedLocation?.groupsFilter to not show virtual groups
.filter {$0.groupType != .VirtualGroup} or .filter {$0.groupType == .Room}var listGroup = RGCore.shared.user.selectedLocation?.groups.filter {$0.groupType != .VirtualGroup}Add group
Section titled “Add group”RGCore.shared.group.createGroup(label: String, desc: String, type: RGBGroupType, locationId: String, completion: ((RGBGroup?, (Error)?) -> ())?)| Name | Description |
|---|---|
| label | The group’s name |
| desc | The group type (Ex: Living room, Kitchen, …) |
| locationId | The location UUID |
| type | .Room : real group, .VirtualGroup : Virtual group |
| completion | Check error |
Modify group
Section titled “Modify group”RGCore.shared.group.updateGroup(id: String, label: String, desc: String, completion: RGBCompletionObject<RGBGroup?>?)| Name | Description |
|---|---|
| id | The group’s uuid |
| label | The group’s name |
| locationId | The group type (Ex: Living room, Kitchen, …) |
| completion | Check error |
Delete group
Section titled “Delete group”RGCore.shared.group.deletedGroup(id: String, completion: RGBCompletionObject<Bool>?)| Name | Description |
|---|---|
| id | The group’s uuid |
| completion | Check error |
Delete virtual group
Section titled “Delete virtual group”RGCore.shared.group.deletedGroup(id: String, completion: RGBCompletionObject<Bool>?)| Name | Description |
|---|---|
| id | The virtual group’s uuid |
| completion | Check error |
Notification Event
Section titled “Notification Event”Automation
Section titled “Automation”Get list automation in Location
Section titled “Get list automation in Location” let listAutomation = RGCore.shared.user.selectedLocation?.allSmartInLocation.filter({$0.smartType == .automation})Automation type
Section titled “Automation type”Notification
let listNotifications = listAutomation.filter({$0.subType == RGBSmartAutomationType.TYPE_NOTIFICATION.rawValue})Advance
let listOther = Array(Set(smarts).subtracting(listNotifications + listStairSwitch + listSelfReverse))Self Reverse
let listSelfReverse = listAutomation.filter({$0.subType == RGBSmartAutomationType.TYPE_SELF_REVERSE.rawValue})Stair switch
let listStaỉrSwitch = listAutomation.filter({$0.subType == RGBSmartAutomationType.TYPE_STAIR_SWITCH.rawValue})Add Automation
Section titled “Add Automation”Add automation according to usage features
- Stair switch
Get list device support stair switch automation
RGCore.shared.automation.getListDevicesSupport(animationType: RGBAutomationEventType, from: [RGBDevice])| Name | Description |
|---|---|
| animationType | .StairSwitch |
| from | Get list device’s uuid |
Create automation: Stair switch
RGCore.shared.smart.addSmartAutomation(smartTitle: String?, automationType: RGBSmartAutomationType, trigger: [RGBSmartTrigger], commands: [RGBSmartCmd], initSmartCompletionHandler: RGBCompletionObject<RGBSmart?>?, addTriggerCompletionHandler: RGBCompletionObject<RGBSmartTrigger?>?, addCommandCompletionHandler: ((Int, RGBSmartCmd?, (Error)?) -> Void)?, completion: RGBCompletionObject<RGBSmart?>?| Name | Description |
|---|---|
| smartTitle | The name of smart |
| automationType | .TYPE_STAIR_SWITCH |
| trigger | .OWNER : .EXT |
| commands | ? |
| initSmartCompletionHandler | nil |
| addTriggerCompletionHandler | nil |
| addCommandCompletionHandler | nil |
| completion | Check error |
Example
Create trigger
let trigger = RGBSmartTrigger(automationEventType: .StairSwitch, triggerCmdValues: [], triggerElementId: elementId, deviceId: deviceId, locationId: locationId, smartId: nil, triggerType: .OWNER)| Name | Description |
|---|---|
| automationType | .TYPE_STAIR_SWITCH |
| triggerCmdValues | .OWNER : .EXT |
| triggerElementId | ? |
| deviceId | nil |
| locationId | nil |
| smartId | nil |
| completion | Check error |
- Automation: Notification
let trigger = RGBSmartTrigger(automationEventType: .Notification, triggerCmdValues: [eventType], triggerElementId: elementId, deviceId: deviceId, timeJob: timeJob, timeConfig: timeConfig, triggerType: .OWNER)| Name | Description |
|---|---|
| automationEventType | .Notification |
| triggerCmdValues | type RGBSmartTriggerEventType. The Event. Example: press one time: .BTN_PRESS_SINGLE |
| triggerElementId | |
| deviceId | The device’s ID |
| timeJob | [startTime, endTime]. Time format: 00:00 |
| timeConfig | |
| triggerType | nil |
- Automation: Advance
automationEventType: .StateChangelet type = trigger.triggerCmdValues.contains.NO_MOTION) ? RGBSmartAutomationType.TYPE_NOMOTION_DETECTED_SIMULATE: RGBSmartAutomationType. TYPE_MIX_ORRCore. shared. smart.addSmartAutomation(smartTitle: smartTitle,automationType: type, trigger: trigger,commands: 1stCommands) { response, error in...}| Name | Description |
|---|---|
| smartTitle | |
| automationType | |
| trigger | |
| deviceId | The device’s ID |
| timeJob | [startTime, endTime]. Time format: |
| timeConfig | |
| triggerType | nil |
Update Firmware
Section titled “Update Firmware”Check firmware version
Section titled “Check firmware version” RGCore.shared.device.checkFirmwareIsLatestWith(deviceId: String, completion: (isLastestVersion: Bool?, currentVersion: String?, latestVersion: String?)?, (any Error)?) -> Void)| Name | Description |
|---|---|
| deviceId | The uuid of device |
| completion | isLastestVersion: True/False currentVersion: The current firmware version latestVersion: The newest firmware version |
Request update
Section titled “Request update” RGCore.shared.device.requestUpdateFirmwareForDeviceWith(deviceId: String, completion: (_ response: Bool?, (any Error)?) -> Void)| Name | Description |
|---|---|
| deviceId | The uuid of dev |
| completion | true: send request success false: print error |