Sceenic - WatchTogether
  • Watch Together and Synchronization SDKs
  • Watch together SDK
    • Watch Together SDK overview
    • Authentication overview
    • Tutorials
      • Android
        • Android - Java/Kotlin
      • iOS
        • iOS Swift/Objective-c adapter
      • Web
        • Authentication
        • Create a New Project
        • Adding WT SDK library to the project
        • Installing the NPM package
        • Sample application
          • The conference skeleton
          • Connecting to a Session
          • How to turn on and off video and audio
          • How to change video quality
          • Errors handling
          • Leave the call
        • Support
    • API references
      • Android reference
        • Session
        • SessionListener
        • SessionReconnectListener
        • SessionConnectionListener
        • Participant
          • ParticipantType
        • SessionError
      • iOS Swift reference
        • Session
        • SessionDelegate
        • Participant
        • ParticipantActiveSpeakerDelegate
        • ParticipantDelegate
        • LocalParticipant
        • WTError
        • DataTypes
      • iOS Objective-c adapter reference
        • SessionAdapter
        • SessionAdapterDelegate
        • ParticipantAdapter
        • LocalParticipantAdapter
        • ParticipantAdpaterDelegate
        • ParticipantAdapterActiveSpeakerDelegate
        • NSError
        • DataTypes
      • Web reference
        • WT Session
          • WTSession.connect(sToken, pName, uC, m)
          • WTSession.connectAsAViewer(sToken, pName)
          • WTSession.connectWithSharingScreen(sToken, pName)
          • WTSession.disconnect()
          • WTSession.enableStats()
          • WTSession.sendMessage(msg)
          • WTSession.sendPlayerData(time)
          • async WTSession.getSessionState()
        • SessionListeners
          • WTSessionListeners.onConnected(fn)
          • WTSessionListeners.onDisconnected(fn)
          • WTSessionListeners.onStreamCreated(fn)
          • WTSessionListeners.onLocalStreamCreated(fn)
          • WTSessionListeners.onMosReport(fn)
          • WTSessionListeners.offMosReport(fn)
          • WTSessionListeners.onMessageReceived(fn)
          • WTSessionListeners.onSyncData(fn)
          • WTSessionListeners.onIceDisconnected(fn)
        • Participant
          • setMediaQuality
        • ParticipantListeners
        • ErrorsListeners
        • ReconnectListeners
        • MediaDevices
      • Cluster authentication service reference (CAS)
  • Synchronization SDK
    • Synchronization SDK overview
    • Tutorials
      • Android
        • Android - Java/Kotlin
      • iOS
        • iOS - Swift/Objective-c
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
        • v2.0 Migration Guide
    • API references
      • Android reference
        • SynchSDK
        • SynchListener
      • iOS reference
        • SynchSDK
        • SynchListener
      • Web reference
  • Celebrity SDK
    • Celebrity SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API References
      • Web reference
  • Chat SDK
    • Chat SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API Refences
      • Web reference
  • Public Chat SDK
    • Public Chat SDK overview
    • Tutorials
      • Web
        • Installing the NPM package
        • Web - TypeScript/React
    • API Refences
      • Web reference
  • Celebrity Watch Party
    • Web application
    • Android
    • iOS
    • Celebrity View & Fan View
Powered by GitBook
On this page
  • Overview
  • Requirements
  • Authentication
  • Acquiring an Access Token
  • Create a project
  • Adding iOS SynchSDK library to the project
  • Cocoapods
  • Instantiating the SDK
  • Managing synchronization logic
  • Support

Was this helpful?

  1. Synchronization SDK
  2. Tutorials
  3. iOS

iOS - Swift/Objective-c

PreviousiOSNextWeb

Last updated 3 years ago

Was this helpful?

Overview

Follow this step-by-step tutorial to implement the video playback Synchronization SDK.

While the client-side SDK will take care of most of the functionality, in order to make this sample application work, you will need to use the API_KEY provided to you.

  • Full code samples can be found here

Requirements

To complete this guide successfully the following prerequisites are required:

  • A Sceenic account

  • Access key for Synch SDK

  • iOS version 11 or higher

Authentication

An Access Token is needed in order to allow a client to connect to a sync group.

Note: It is important that the client application does not request an Access Token directly from the backend. By doing that you risk exposing the API_TOKEN and API_SECRET.

Acquiring an Access Token

curl -iL --request GET --url https://YOUR_CAS_URL/sync/token --header 'auth-api-key: API_KEY'   --header 'auth-api-secret: API_SECRET'

A successful response will look like that:

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...."
}

Note: Every Sync Token corresponds to one specific sync group only. To allow two different clients to connect to the same group, the clients need to use the same Access Token.

Create a project

  • Open Xcode and create a new project

  • Choose a Single View application

  • Configure your product organization, bundle, and team names

  • Set the application location on your computer and press “create”

Adding iOS SynchSDK library to the project

You can drag SynchSDK.framework to the project tree and use this library manually.

Cocoapods

  • Create a folder with the name "SynchSDK" at the root of the project

  • Copy all files ("SynchSDK.framework","SynchSDK.podspec") to the folder

  • [When using the Objective-c adapater] - do the following extra steps

    • Create a folder with the name "SynchSDK" at the root of the project

    • Copy all files ("SynchSDKAdapter.framework","SynchSDKAdapter.podspec") to the folder

Instantiating the SDK

  • Initialize SynchSDK object:

let synchSDK = SyncSDK?

do {
    synchSDK = try SyncSDK(accessToken: token, userName: userName) //token - authorization token, username - name of user
    synchSDK.attachListener(self)// self - SynchListener object
} catch {
    print(error)// error is SynchTokenError
    //fallback logic
}
    

@interface YourViewController () <SynchListenerAdapter>
@property (nonatomic, strong) SynchSDKAdapter* synch;
end;

- (void)viewDidLoad {
    [super viewDidLoad];
    NSError* err = nil;
    _synch = [[SynchSDKAdapter alloc] initWithAccessToken: token username:@"userName" error: &err];
    if (err != NULL) {
        NSLog(@"%@", err);
        //fallbacklogic
    } 
    [_synch attachListener: self];
    

  • Start synchronization - To start using the SynchSDK object you will require a SynchSdk’s URL and a valid Access Token to be available before connecting.

synchSDK.startSynchronize()

[synch startSynchronize];

  • Stop synchronization

synchSDK.stopSynchronize()

[synch stopSynchronize];

Managing synchronization logic

To manage the synchronization logic we provided several callbacks and will allow you to customize the interactions you need.

  • The SynchListener interface, which the StreamView implements in the sample application, will allow you to control the flow of logic of the Synchronization you are managing


extension StreamView: SynchListener{
    func onClientList(clientList: [Client]) {
        // remote client joined to the group, update ui using adapter
    }
    
    func onSetPlaybackRate(rate: Float) {
        // setting playback rate
    }
    
    func onPlaybackFromPosition(position: Int, participantId: String) {
        // playback from position
    }
    
    func onGetPlayerPosition() -> Int {
        // getting player position
    }
    
    func onGetPlaybackRate() -> Float {
        // getting playback rate
    }
    
    func onSyncInfo(accuracy: Float, delta: Int) {
        // information about synchronization's accuracy and delta
    }
    func onResumePlay(participantId: String) { 
        player?.play()
    }
    
    func onPause(participantId: String) {
        player?.pause()
    }
    
}

- (void)onClientListWithClientList:(NSArray<ClientAdapter *> * _Nonnull)clientList {
    // remote client joined to the group, update ui using adapter
}

- (float)onGetPlaybackRate {
     // setting playback rate
}

- (NSInteger)onGetPlayerPosition {
        // getting player position
}

- (void)onPlaybackFromPositionWithPosition:(NSInteger)position participantId:(NSString*) participantId {
   // playback from position
}

- (void)onSetPlaybackRateWithRate:(float)rate {
     // getting playback rate
}

- (void)onSyncInfoWithAccuracy:(float)accuracy delta:(NSInteger)delta {
     // information about synchronization's accuracy and delta
}

- (void)onPauseWithParticipantId:(NSString *)participantId {
    [_player pause];
}

- (void)onResumePlayWithParticipantId:(NSString *)participantId{
    [_player play];
}

Support

The Access Token is a JWT token - more about jwt you can read - .

You can get your API_KEY and API_SECRET in your private area, .

Download library () package and unpack it

You can use to install SynchSDK by adding it to your Podfile pod 'SynchSDK', :path => './SynchSDK'

You can use to install SynchSDK by adding it to your Podfile pod 'SynchSDKAdapter', :path => './SynchSDKAdapter'

Need technical support? contact us at .

Swift code samples
Objective-c adapter code samples
Xcode
here
here
Private area
Cocoapods
Cocoapods
Support@sceenic.co