Please Wait

Loading..

iOS Swift SDK 1.0.0

Create amazing realtime applications easily with Yalgaar iOS Swift SDK

iOS Swift SDK

1 Connect To Yalgaar

Requirement :

Supports iOS version 8.0 or above.

Download package and include framework into project.

First adopt YalgaarClientDelegate and implement the instance methods of it. Now, create an object of YalgaarClient class and assign delegate object to it.

var objYalgaarClient  = YalgaarClient.init()
objYalgaarClient.delegate = delegate_object

To connect to a Yalgaar client, use following method. It must have valid Client Key.

func connectWithClientKey(_ clientKey: String, isSecure: Bool, error: inout NSError?)         
func connectWithClientKey(_ clientKey: String, isSecure: Bool, uuid: String?, error: inout NSError?)      
func connectWithClientKey(_ clientKey: String, isSecure: Bool, aesSecretKey: String, aesKeyType: AESKeyType, error: inout NSError?)      
func connectWithClientKey(_ clientKey: String, isSecure: Bool, uuid: String?, aesSecretKey: String?, aesKeyType: AESKeyType?, error: inout NSError?)

Parameter:

  • clientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: String
  • isSecure
    • Description: Preference for which kind of connection required, secure or non-secure.
    • DataType: Bool
  • error
    • Description: Object of NSError with address which contains error code if any error occurs.
    • DataType: NSError?
  • uuid
    • Description: UUID is unique string for each user and can be used to access presence of other users.
    • DataType: String?
  • aesSecretKey
    • Description: AESSecreteKey to transmit data over network using encryption.
    • DataType: String
  • keyType
    • Description: User can choose one from 128, 192 and 256 key type.
    • DataType: enum of AESKeyType
  • Response Delegates
    • Description: If connection failed or any error occurred: Check error parameter, if it is not nil then check error code for error classification
      • func connectionError(_ error: NSError?) -called when any network error occurred during connect to Yalgaar.
      • func connectionAlreadyEstablished(_ yalgaarClient: NSObject) -called when connection already exist on this object.
      • func didConnected() -called when connection done successfully.


2 Publish Message

To publish message, use following method.

func publishWithChannel(_ channel: String, message: String, error: inout NSError?)

Parameter:

  • channel
    • Description : Channel name on which data will be published.
    • DataType : String
  • message
    • Description : Data to be send.
    • DataType : String
  • error
    • Description : Object of NSError with address which contains error code if any error occurs.
    • DataType : NSError?
  • Response Delegates
    • Description: Below delegate will be called with status and error (if any) during publish process.
      • func publishStatus(_ status: Bool, error: NSError?)


3 Subscribe Message

To subscribe message, use following method.

func subscribeWithChannel(_ channel:String, error:inout NSError?)
func subscribeWithChannels(_ channels: [String], error:inout NSError?)

Parameter:

  • channel
    • Description: Subscription Channel in form of string. Channel name is CASE SENSITIVE.
    • DataType: String
  • channels
    • Description: Array having one or more subscription Channels in form of string. Channel name is CASE SENSITIVE.
    • DataType: [String]
  • error
    • Description: Object of NSError with address which contains error code if any error occurs.
    • DataType: NSError?
  • Response Delegates
    • Description: If connection failed or any error occurred: Check error parameter, if it is not nil then check error code for error classification.
      • func dataReceivedForSubscription(_ data: String, channels: [String]) -called when receive data (in form of string).
      • func didSubscribed() -called when successfully subscription of channel(s).
      • func subscribeError(_ error: NSError?) -called with error code if any error occurred during subscription.


4 Unsubscribe Message

To unsubscribe message,use following method.

func unsubscribeWithChannel(_ channel: String, error: inout NSError?)
func unsubscribeWithChannels(_ channels: [String], error: inout NSError?)

Parameter:

  • channel
    • Description: Unsubscription Channel in form of string. Channel name is CASE SENSITIVE.
    • DataType: String
  • channels
    • Description: Array having one or more unsubscription Channels in form of string. Channel name is CASE SENSITIVE.
    • DataType: [String]
  • error
    • Description: Object of NSError with address which contains error code if any error occurs.
    • DataType: NSError?
  • Response Delegates
    • Description: If connection failed or any error occurred: Check error parameter, if it is not nil then check error code for error classification
      • func didUnsubscribed() -called when successfully unsubscription of channel(s).


5 User's presence

Get data when some one subscribe Channel(s) that you have already subscribed. Below delegate function called when someone subscribe to Channel that is common into your subscribed Channel(s).

func dataReceivedOfPresenceForAction(_ action: PresenceAction, channel: String, uuid: String, dateTime: Date)

Parameter:

  • action
    • Description: User getting bind or unbind.
    • DataType: PresenceAction
  • channel
    • Description: Name of Channel on which user bind or unbind.
    • DataType: String
  • uuid
    • Description: User id of which presence data are passed.
    • DataType: String
  • dateTime
    • Description: Date and time on which user bind or unbind.
    • DataType: Date


6 Get User List

To get list of all user subscribe with specified channel name, use following method.

func getUUIDListForChannel(_ channel: String, error: inout NSError?)

Parameter:

  • channel
    • Description: Name of Channel that is consumed by user.
    • DataType: String
  • error
    • Description: Reference of NSError send as parameter, if its value is not nil then no error occurred, otherwise see error code.
    • DataType: NSError?
  • Response Delegates
    • Description: In response of above function call, below delegate function will be called which contains list of user along with its channel name.
      • func dataReceivedWithUUID(_ arrUUID: [String], channel: String) -called in response of above function which contains list of user along with its Channel name.
      • func getUUIDListChannelListError(_ error: NSError?) called when any error occur.


7 Get Channel List

To get list of all channels subscribed by specified user, use following method.

func getChannelListForUUID(_ uuid: String, error: inout NSError?)

Parameter:

  • uuid
    • Description: UUID of which user need to get consumed Channels.
    • DataType: String
  • error
    • Description: Reference of NSError send as parameter, if its value is not nil then no error occurred, otherwise see error code.
    • DataType: NSError?
  • Response Delegates
    • Description: In response of above function, below delegate function will be called which contains list of channels along with its UUID.
      • func dataReceivedWithChannels(_ arrChannels: [String], uuid:String) -called in response of above function which contains list of Channels along with its UUID.
      • func getUUIDListChannelListError(_ error: NSError?) -called when any error occur.


8 Get Message History

To get the already published messages, use following method.

func messageHistoryWithChannel(_ channel: String, messageCount: Int, error: inout NSError?)

Parameter:

  • channel
    • Description : Channel name from which messages will be fetched.
    • DataType : String
  • messageCount
    • Description : Number of messages to get. (maximum 100)
    • DataType : Int
  • error
    • Description : Object of NSError with address which contains error code if any error occurs.
    • DataType : NSError?
  • Response Delegates
    • Description: In response of above function call, below delegate function will be called with array of history data.
      • func dataReceivedForMessageHistroy(_ data: NSArray) -called in response of above function which contains array of history data.
      • func messageHistoryStatus(_ status: Bool, error: NSError?) -called when any error occur with status and error object.


9 Disconnect

To disconnect connection with Yalgaar Client, use following method.

func disconnect()

Parameter:

  • Response Delegates
    • func didDisconnected() -called when successfully disconnected.


You can publish/subscribe message like so :

Below is header file of ViewController class, which adopt YalgaarClientDelegate and implement it.

import YalgaarSwiftSDK
class ViewController: UIViewController, YalgaarClientDelegate {	
	var objYalgaarClient : YalgaarClient?
	override func viewDidLoad() {
        ...
        objYalgaarClient = YalgaarClient.init()
        objYalgaarClient!.delegate = self
		var errorClientID : NSError?        	   
        objYalgaarClient!.connectWithClientKey("ClientID", isSecure:true, error:&errorClientID)
		if errorClientID != nil {
            print("Connection Error: \(errorClientIDValidation!.code), \(errorClientIDValidation!.userInfo["reason"] as! String)")            
        }

		var errorSub : NSError?
        objYalgaarClient!.subscribeWithChannel("YourChannel", error: &errorSub)
       	if errorSub != nil {
            print("Subscribe Error: \(errorSub!.code), \(errorSub!.userInfo["reason"] as! String)")            
        }

		var errorPubData : NSError?        
        objYalgaarClient!.publishWithChannel("YourChannel", message: "This is iOS Swift SDK Example", error: &errorPubData)        
        if errorPubData != nil {
            print("Publish Error: \(errorPubData!.code), \(errorPubData!.userInfo["reason"] as! String)")            
        }
	
		objYalgaarClient!.disconnect()
		...
	}
	// YalgaarClient delegate methods
	...
	func dataReceivedForSubscription(_ data: String, channels:[String]){
       	 	print("Data received: \(data)") 
	}
	...
}