Spark iOS SDK written in swift.
Here are the steps to integrate SparkSDK into your Xcode project using CocoaPods:
-
Install CocoaPods:
gem install cocoapods
-
Setup Cocoapods:
pod setup
-
Create a new file "Podfile" with following content in your project directory::
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! target 'SparkSDKDemo' do pod 'SparkSDK' end
-
Install SparkSDK from your project directory:
pod install
Below is code of a demo of the SDK usage
-
Setup SDK with Spark access token
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let sparkAccessToken = "Yjc5ZTYyMDEt..." Spark.initWith(accessToken: sparkAccessToken) return true }
-
Setup SDK with app infomation, and authorize access to Spark service
class LoginViewController: UIViewController { @IBAction func loginWithSpark(sender: AnyObject) { let clientId = "C90f769..." let clientSecret = "64e252..." let scope = "spark:people_read spark:rooms_read spark:rooms_write spark:memberships_read spark:memberships_write spark:messages_read spark:messages_write" let redirectUri = "SparkSDKDemo://response" Spark.initWith(clientId: clientId, clientSecret: clientSecret, scope: scope, redirectUri: redirectUri, controller: self) } }
-
Register device
Spark.phone.register() { success in if !success { print("Failed to register device.") } }
-
Use Spark service
// IM example do { // Create a new room let room = try Spark.rooms.create(title: "Hello World") print("\(room.title!), created \(room.created!): \(room.id!)") // Add a coworker to the room try Spark.memberships.create(roomId: room.id!, personEmail: "[email protected]") // List the members of the room let memberships = try Spark.memberships.list(roomId: room.id!) for membership in memberships { print("\(membership.personEmail!)") } // Post a text message to the room try Spark.messages.postToRoom(roomId: room.id!, text: "Hello World") // Share a file with the room try Spark.messages.postToRoom(roomId: room.id!, files: "http://example.com/hello_world.jpg") } catch let error as NSError { print("Error: \(error.localizedFailureReason)") } // Calling example // Make a call var outgoingCall = Spark.phone.dial("[email protected]", option: MediaOption.AudioVideo(local: ..., remote: ...)) { success in if !success { print("Failed to dail") } } // Recieve a call class IncomingCallViewController: UIViewController, PhoneObserver { override func viewWillAppear(...) { ... PhoneNotificationCenter.sharedInstance.addObserver(self) } override func viewWillDisappear(...) { ... PhoneNotificationCenter.sharedInstance.removeObserver(self) } func callIncoming(call: Call) { // Show incoming call toast view } ... }