Installation guide

Installation

Mobile SDK is built using Moya framework. In order to use CMMobileSDK you should import mentioned framework as well. There are few ways to import these frameworks, however the fastest one is to use CocoaPods.

ūüďė

Moya and SwiftyJSON frameworks are used in the Demo app to perform additional calls with REST API like authentication, retrieving list of recordings. Feel free to use example code and extend it with other API calls.

Requirements

MobileSDK v5.2.9
iOS 14.0
Moya 10+
Swift 5.1.2

Importing required frameworks into your project

  • Install CocoaPods on your Mac if necessary (follow instructions at official site).
  • Open Terminal.
  • Run cd command to folder which contains your project.
  • Run pod init command, it will create Podfile at containing folder.
  • Open Podfile and insert next text:
platform :ios, '10.0' # your supported iOS version
use_frameworks!
 
target 'YourAppTarget' do
  pod 'Moya', :git => 'https://github.com/Moya/Moya.git', :tag => '14.0'
  pod 'SwiftyJSON'
end
  • Save and close Podfile
  • Run pod install commands. Note: close Xcode before executing command.
  • YourProjectName.xcworkspace file was generated, open your project with this file now, not YourProjectName.xcodeproj.

Importing Mobile SDK into your project

  • Add CMMobileSDK.framework file to your project.
  • Add CMMobileSDK.framework to Embedded Binaries section of your target's General tab.
  • Add next line at file where you plan to use it
import CMMobileSDK
#import <CMMobileSDK/CMMobileSDK-Swift.h> // to use CameraWizard/NuboCamWizard/AccessTokenProvider modules.
#import <CMMobileSDK/CMMobileSDK.h> 			// to use CameraSniffer/CameraStreamer modules.
  • To support cameras with two-way audio, please make sure to add NSMicrophoneUsageDescription to your app's Info.list.

Usage examples

import CMMobileSDK

// set access token provider delegate so mobile SDK will be able to retrieve access token when needed
CMAccessTokenProvider.delegate = yourAccessTokenProviderDelegateInstance
 
// init and start sniffing
let sniffer = CMCameraSniffer(delegate: yourSnifferDelegateInstance)
sniffer.startSniffing()
 
// search for device manually if sniffer cannot detect it automatically
sniffer.searchDeviceManually(at: ipAddressOfCamera)
 
// init wizard and add some device
let wizard = CMCameraWizard(delegate: yourWizardDelegateInstance)
wizard.addDevice(someDeviceReturnedBySniffer, named: nameForNewCamera, atZone: someZoneIdFetchedByYou)
 
// prepare streamer
let streamer = CMCameraStreamer(layer: someLayerToRenderPictureIn)
streamer.delegate = yourCameraStreamerDelegate
streamer.renderMode = CMCameraStreamerRenderModeAspectFit
streamer.currentItem = CMStreamerItem.init(cameraId: cameraIdFetchedByYou, recordingId: recordingIdFetchedByYou)
 
// wait until status will change to readyToPlay, after that you can manipulate with playback
if streamer.status == CMCameraStreamerStatusReadyToPlay {
  streamer.rate = 0.0 // pause stream.
  streamer.rate = 1.0 // play stream at rate x1.
}
 
// you can seek if seeking capability is supported
let seekingSupported = UInt8(streamer.currentItem.capabilitiesMask.rawValue) & UInt8(CMStreamerItemCapabilitiesMaskCanSeek.rawValue) > 0
if seekingSupported {
  streamer.seek(to: streamer.currentItem.duration * 0.5) // seek to middle of footage.
}
 
// you can step if stepping capability is supported
let steppingSupported = UInt8(streamer.currentItem.capabilitiesMask.rawValue) & UInt8(CMStreamerItemCapabilitiesMaskCanStep.rawValue) > 0
if steppingSupported {
  streamer.step(by: 10) // move 10 frames further.
  streamer.step(by: -2) // move 2 frames backwards.
}
 
// you can speedPlay if speedPlay capability is supported
let speedPlaySupported = UInt8(streamer.currentItem.capabilitiesMask.rawValue) & UInt8(CMStreamerItemCapabilitiesMaskCanSpeedPlay.rawValue) > 0
if speedPlaySupported {
  streamer.rate = 3.0 // play stream at rate x3. 
}
 
// start and stop sending audio to camera. Note that live stream should be active otherwise you will receive error
let audioStreamingSupported = UInt8(streamer.currentItem.capabilitiesMask.rawValue) & UInt8(CMStreamerItemCapabilitiesMaskCanStreamAudio.rawValue) > 0
if audioStreamingSupported {
  streamer.startAudioStreaming()
  streamer.stopAudioStreaming()
}
 
// init Nubocam wizard and add some Nubocam. Check NuboCamWizard page for more information
let nuboCamWizard = CMNuboCamWizard(delegate: yourNuboCamWizardDelegateInstance)
nuboCamWizard.prepareForConnection(with: ["zoneId" : 1234])
nuboCamWizard.connectToCamera() // Note: you should connect to Nubocam's wifi hotspot via iOS Settings app before calling this method
nuboCamWizard.refreshWifiList()
nuboCamWizard.connectCamera(to: wifiReturnedByPreviousMethod, withName: "My first Nubocam")
 
// init Doorbell wizard and add some Doorbell camera. Check DoorbellWizard page for more information
let doorbellWizard = CMDoorbellWizard(delegate: yourDoorbellWizardDelegateInstance)
doorbellWizard.prepareForConnection(with: ["zoneId" : 1234])
doorbellWizard.connectToCamera() // Note: you should connect to Doorbell's wifi hotspot via iOS Settings app before calling this method
doorbellWizard.refreshWifiList()
doorbellWizard.connectCamera(to: wifiReturnedByPreviousMethod, withName: "My first Doorbell")
#import <CMMobileSDK/CMMobileSDK-Swift.h>
#import <CMMobileSDK/CMMobileSDK.h>	

// set access token provider delegate so mobile SDK will be able to retrieve access token when needed
CMAccessTokenProvider.delegate = yourAccessTokenProviderDelegateInstance
 
// init and start sniffing
CMCameraSniffer* sniffer = [[CMCameraSniffer alloc] initWithDelegate:yourSnifferDelegateInstance];
[sniffer startSniffing];
 
// search for device manually if sniffer cannot detect it automatically
[sniffer searchDeviceManuallyAt: ipAddressOfCamera];
 
// search for device manually if sniffer cannot detect it automatically
[sniffer searchDeviceManuallyAt: ipAddressOfCamera];
 
// init wizard and add some device
CMCameraWizard* wizard = [[CMCameraWizard alloc] initWithDelegate:yourWizardDelegateInstance];
[wizard addDevice:someDeviceReturnedBySniffer named:nameForNewCamera atZone:someZoneIdFetchedByYou];
 
// prepare streamer
let streamer = [[CMCameraStreamer alloc] initWithLayer:someLayerToRenderPictureIn];
streamer.delegate = yourCameraStreamerDelegate;
streamer.renderMode = CMCameraStreamerRenderModeAspectFit;
streamer.currentItem = [CMStreamerItem itemWithCameraId:cameraIdFetchedByYou recordingId:recordingIdFetchedByYou];
 
// wait until status will change to readyToPlay, after that you can manipulate with playback
if (streamer.status == CMCameraStreamerStatusReadyToPlay) {
  streamer.rate = 0.0; // pause stream.
  streamer.rate = 1.0; // play stream at rate x1.
}
 
// you can seek if seeking capability is supported
BOOL seekingSupported = (streamer.currentItem.capabilitiesMask & CMStreamerItemCapabilitiesMaskCanSeek) > 0;
if (seekingSupported) {
  [streamer seekTo: streamer.currentItem.duration * 0.5]; // seek to middle of footage.
}
 
// you can step if stepping capability is supported
BOOL steppingSupported = (streamer.currentItem.capabilitiesMask & CMStreamerItemCapabilitiesMaskCanStep) > 0;
if (steppingSupported) {
  [streamer stepBy: 10]; // move 10 frames further.
  [streamer stepBy: -2]; // move 2 frames backwards.
}
 
// you can speedPlay if speedPlay capability is supported
BOOL speedPlaySupported = (streamer.currentItem.capabilitiesMask & CMStreamerItemCapabilitiesMaskCanSpeedPlay) > 0;
if (speedPlaySupported) {
  streamer.rate = 3.0; // play stream at rate x3. 
}
 
// start and stop sending audio to camera. Note that live stream should be active otherwise you will receive error
BOOL audioStreamingSupported = (streamer.currentItem.capabilitiesMask & CMStreamerItemCapabilitiesMaskCanStreamAudio) > 0;
if (audioStreamingSupported) {
  [streamer startAudioStreaming];
  [streamer stopAudioStreaming];
}
 
// init Nubocam wizard and add some Nubocam. Check NuboCamWizard page for more information
CMNuboCamWizard *nuboCamWizard = [[CMNuboCamWizard alloc] initWithDelegate:yourNuboCamWizardDelegateInstance];
[nuboCamWizard prepareForConnectionWith:@{@"zoneId" : @(1234)}];
[nuboCamWizard connectToCamera]; // Note: you should connect to Nubocam's wifi hotspot via iOS Settings app before calling this method
[nuboCamWizard refreshWifiList];
[nuboCamWizard connectCameraTo:wifiReturnedByPreviousMethod withName:@"My first Nubocam"];
 
// init Doorbell wizard and add some Doorbell camera. Check DoorbellWizard page for more information
CMDoorbellWizard *doorbellWizard = [[CMDoorbellWizard alloc] initWithDelegate:yourDoorbellWizardDelegateInstance];
[doorbellWizard prepareForConnectionWith:@{@"zoneId" : @(1234)}];
[doorbellWizard connectToCamera]; // Note: you should connect to Doorbell's wifi hotspot via iOS Settings app before calling this method
[doorbellWizard refreshWifiList];
[doorbellWizard connectCameraTo:wifiReturnedByPreviousMethod withName:@"My first Doorbell"];