Home

Awesome

Overview

Cisco Spark iOS SDK enables you to embed Cisco Spark calling and meeting experience into your iOS mobile application. The SDK provides APIs to make and receive audio/video calls. In order to receive audio/video calls, the user needs to be notified when someone is calling the user.

This sample Webhook/Push Notification Server demonstrates how to write a server application to receive Incoming Call Notification from Cisco Spark and use Apple Push Notification Service to notify the mobile application.

This sample is built upon apns4j and Sprint Boot. It is designed to be deployed and run on Heroku. But it can be deployed and run on other environments with minimal changes.

For more information about iOS remote notification, please see Apple developer guide.

How it works

Assuming this sample Webook/Push Notification Server has been deployed on the public Internet, the following describes the webhooks and push notification workflow step by step.

Spark-IOSSDK-APNS

  1. Register to the Apple Push Notification Service (APNs) when your iOS application is launching.

  2. The APNs returns a device token to the application.

  3. Register the device token returned by the APNs and the user Id of current user to the Webhook/Push Notification Server. The Server stores these information locally in a database.

    let paramaters: Parameters = [
    	"email": email,
    	"voipToken": voipToken,
    	"msgToken": msgToken,
    	"personId": personId
    ]
    Alamofire.request("https://example.com/register", method: .post, parameters: paramaters, encoding: JSONEncoding.default).validate().response { res in
    	// ...
    }
    
  4. After the user logs into Cisco Spark,use Webhook API to create an webhook at Cisco Spark cloud. The target URL of the webhook must be the /webhook REST endpoint of this server. The URL has to be publicly accessible from the Internet.

    spark.webhooks.create(name: "Incoming Call Webhook", targetUrl: targetUrl, resource: "callMemberships", event: "created", filter: "state=notified&personId=me") { res in
    	switch res.result {
            case .success(let webhook):
            	// perform positive action
            case .failure(let error):
            	// perform negative action
        	}
    }
    
  5. The remote party makes a call via Cisco Spark.

  6. Ciso Spark receives the call and triggers the webhook. The incoming call event is sent to the target URL, which should be /webhook REST endpoint of this Webhook/Push Notification server.

  7. The Webhook/Push Notification Server looks up the device token from the database by the user Id in the incoming call event, then sends the notification with the device token and incoming call information to the APNs.

  8. The APNs pushs notification to the iOS device.

  9. Your iOS application gets the push notification and uses the SDK API to accept the call from Spark Cloud.

For more details about Step 1 and 2, please see Apple Push Notifications Guide

For more details about Step 3 and 6, please see Cisco Spark Webhooks Explained

Deployment

The sample application can be easily deployed as a Java application on the Heroku.

  1. Create an Herko account and set up the Heroku environment.

  2. Create a new Heroku app.

  3. Clone the sample code to a local directory.

    git clone git@github.com:ciscospark/spark-ios-sdk-example-push-notification-server.git 
    
  4. Copy your Apple Push Certificates to ./spark-ios-sdk-example-push-notification-server/.jdk-overlay/jre/lib/security.

    Sending and receiving push notifications requires you to create Apple Push Certificates. For this sample application, you should create and upload three certificates corresponding, one for each type: Development, Production and VoIP Services.

    Apple Push Certificates are generated from the Apple Developer Member Center which requires a valid Apple ID to login.

  5. Deploy the application to Heroku.

    heroku git:remote -a YOUR_APP_NAME
    git add .
    git commit -am "First Deploy"
    git push heroku master
    

REST API endpoints and Usage

The sample Webhook/Push Notification server provides three REST API endpoints.