Giter Club home page Giter Club logo

spark-ios-sdk's Introduction

Cisco Spark iOS SDK

CocoaPods Travis CI license

The Cisco Spark iOS SDK makes it easy to integrate secure and convenient Cisco Spark messaging and calling features in your iOS apps.

This SDK is written in Swift 3 and requires iOS 9 or later.

Table of Contents

Install

Assuming you already have an Xcode project, e.g. MySparkApp, for your iOS app, here are the steps to integrate the Spark iOS SDK into your Xcode project using CocoaPods:

  1. Install CocoaPods:

    gem install cocoapods
  2. Setup CocoaPods:

    pod setup
  3. Create a new file, Podfile, with following content in your MySparkApp project directory:

    source 'https://github.com/CocoaPods/Specs.git'
    
    platform :ios, '9.0'
    use_frameworks!
    
    target 'MySparkApp' do
      pod 'SparkSDK'
    end
  4. Install the Spark iOS SDK from your MySparkApp project directory:

    pod install

Usage

To use the SDK, you will need Cisco Spark integration credentials. If you do not already have a Cisco Spark account, visit Spark for Developers to create your account and register your integration. Your app will need to authenticate users via an OAuth grant flow for existing Cisco Spark users or a JSON Web Token for guest users without a Cisco Spark account.

See the iOS SDK area of the Spark for Developers site for more information about this SDK.

Example

Here are some examples of how to use the iOS SDK in your app.

  1. Create the Spark instance using Spark ID authentication (OAuth-based):

    let clientId = "$YOUR_CLIENT_ID"
    let clientSecret = "$YOUR_CLIENT_SECRET"
    let scope = "spark:all"
    let redirectUri = "Sparkdemoapp://response"
    
    let authenticator = OAuthAuthenticator(clientId: clientId, clientSecret: clientSecret, scope: scope, redirectUri: redirectUri)
    let spark = Spark(authenticator: authenticator)
    
    if !authenticator.authorized {
        authenticator.authorize(parentViewController: self) { success in
            if !success {
                print("User not authorized")
            }
        }
    }
  2. Create the Spark instance with Guest ID authentication (JWT-based):

    let authenticator = JWTAuthenticator()
    let spark = Spark(authenticator: authenticator)
    
    if !authenticator.authorized {
        authenticator.authorizedWith(jwt: myJwt)
    }
  3. Register the device to send and receive calls:

    spark.phone.register() { error in
        if let error = error {
            // Device not registered, and calls will not be sent or received
        } else {
            // Device registered
        }
    }
  4. Use Spark service:

    spark.rooms.create(title: "Hello World") { response in
        switch response.result {
        case .success(let room):
            // ...
        case .failure(let error):
            // ...
        }
    }
    
    // ...
    
    spark.memberships.create(roomId: roomId, personEmail: email) { response in
        switch response.result {
        case .success(let membership):
            // ...
        case .failure(let error):
            // ...
        }
    }
    
    // ...
    
    spark.messages.post(personEmail: email, text: "Hello there") { response in
        switch response.result {
        case .success(let message):
            // ...
        case .failure(let error):
            // ...
        }
    }
  5. Make an outgoing call:

    spark.phone.dial("[email protected]", option: MediaOption.audioVideo(local: ..., remote: ...)) { ret in
        switch ret {
        case .success(let call):
            call.onConnected = {
                // ...
            }
            call.onDisconnected = { reason in
                // ...
            }
        case .failure(let error):
            // failure
        }
    }
  6. Receive a call:

    spark.phone.onIncoming = { call in
        call.answer(option: MediaOption.audioVideo(local: ..., remote: ...)) { error in
        if let error = error {
            // success
        }
        else {
            // failure
        }
    }
  7. Make an room call:

    spark.phone.dial(roomId, option: MediaOption.audioVideo(local: ..., remote: ...)) { ret in
        switch ret {
        case .success(let call):
            call.onConnected = {
                // ...
            }
            call.onDisconnected = { reason in
                // ...
            }
            call.onCallMembershipChanged = { changed in
                switch changed {
                case .joined(let membership):
                    //
                case .left(let membership):
                    //
                default:
                    //
                }                
            }            
        case .failure(let error):
            // failure
        }
    }
  8. Screen share (view only):

    spark.phone.dial("[email protected]", option: MediaOption.audioVideoScreenShare(video: (local: ..., remote: ...))) { ret in
        switch ret {
        case .success(let call):
            call.onConnected = {
                // ...
            }
            call.onDisconnected = { reason in
                // ...
            }
            call.onMediaChanged = { changed in
                switch changed {
                    ...
                case .remoteSendingScreenShare(let sending):
                    call.screenShareRenderView = sending ? view : nil
                }
            }
        case .failure(let error):
            // failure
        }
    }

License

© 2016-2017 Cisco Systems, Inc. and/or its affiliates. All Rights Reserved.

See LICENSE for details.

spark-ios-sdk's People

Contributors

kliu avatar xu0101 avatar qucui avatar rwpeek avatar joe-still avatar xiuwwu avatar dciobanu avatar bbender avatar asynchrony-ringo avatar pauzhang-cisco avatar

Watchers

James Cloos avatar Jason Wu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.