Skip to content

iOS 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.

  1. Update CocoaPods to the latest version. For more information about CocoaPods, see CocoaPods Guides.

  2. Add the following code block to the Podfile:

platform :ios, "13.0"
target "Project_Name" do
use_frameworks!
pod "RogoCore"
end
  1. In the root directory of your project, run pod install.

To using RogoCore Library:

import RogoCore

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

  1. Sign in to the dashboard

Dashboard: dashboard.rogo.com.vn

No partner yet? Create one.

  1. Select Project.

  2. Create Project.

Choose Add Project > Enter Project Name > OK Fill infomation for project

Name Description
Name The name of Project.
  1. 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
  1. Select Apps.

Choose App > Get appKey and appSecret

The demo app in the sample project is used for reference only. Do not use the demo app for commercial purposes.

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.

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

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.
RGCore.shared.auth.signUp(email: String,
username: String,
phone: String,
password: String,
completion: RGBCompletionObject<RGBAuthResponse>)

Parameter

Name Description
email 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))
}
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
}
RGCore.shared.auth.signInWithUsername(username: String,
password: String,
completion: RGBCompletionObject<RGBAuthResponse>)
Name Description
username The username
password The password
completion The success callback
RGCore.shared.auth.signInWithEmail(email: String,
password: String,
completion: RGBCompletionObject<RGBAuthResponse>)
Name Description
email The user’s email
password The password
completion The success callback

Send verify code

RGCore.shared.auth.requestVerifyCode(email: String,
completion: RGBCompletionObject<RGBAuthResponse>)
Name Description
email 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
RGCore.shared.auth.signOut(completion: response: RGBAuthResponse, (any Error)?) -> Void)
Name Description
completion nil: sign out is success

Get all location in account

RGCore.shared.user.locations
RGCore.shared.user.selectedLocation
Name Description
email The user’s email
password The password
completion nill: success
RGCore.shared.user.setSelectedLocation(locationId: String)
Name Description
locationId The location’s ID
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
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
RGCore.shared.user.deletedLocations(id: String, completion: RGBCompletionObject<Bool>?)
Name Description
id Location’s uuid
completion The success callback
RGCore.shared.device.scanAvailableWileDevice(timeout: Int, completion: RGBCompletionObject<RGBMeshScannedDevice?>?)
Name Description
timeout Set timeout
completion The success callback
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
RGCore.shared.device.cancelWileConfig()
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
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
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)
}
RGCore.shared.device.stopScanRFDevice(gateWay: RGBDevice)
Name Description
gateWay The locationID

Get all devicein location

RGCore.shared.user.selectedLocation?.allDevicesInLocation

Using filter function

Example:

listDevice = RGCore.shared.user.selectedLocation?.allDevicesInLocation.filter {$0.groupID == selectedGroup.uuid}
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
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
}
RGCore.shared.device.deleteDeviceWith(deviceUUID: String, completion: RGBCompletionObject<RGBDevice?>?)
Name Description
deviceUUID Device’s uuid
completion check error
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
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
RGCore.shared.group.removeGroupMember(deviceWithUUID: String, fromGroupWith: RGBGroup, observer: AnyObject?, completion: RGBCompletionObject<RGBGroupMember?>?)
  1. 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
  1. 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()
}
  1. 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>
}
}
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
RGCore.shared.user.selectedLocation?.groups

Filter 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}
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
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
RGCore.shared.group.deletedGroup(id: String, completion: RGBCompletionObject<Bool>?)
Name Description
id The group’s uuid
completion Check error
RGCore.shared.group.deletedGroup(id: String, completion: RGBCompletionObject<Bool>?)
Name Description
id The virtual group’s uuid
completion Check error
let listAutomation = RGCore.shared.user.selectedLocation?.allSmartInLocation.filter({$0.smartType == .automation})

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 according to usage features

  1. 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
  1. 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
  1. Automation: Advance
automationEventType: .StateChange
let type = trigger.triggerCmdValues.contains.NO_MOTION) ? RGBSmartAutomationType.TYPE_NOMOTION_DETECTED_SIMULATE: RGBSmartAutomationType. TYPE_MIX_OR
RCore. 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
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
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