Please Wait

Loading..

iOS Objective C SDK 1.0.0

Create amazing realtime applications easily with Yalgaar iOS Objective C SDK

iOS SDK

1 Connect To Yalgaar

Requirement :

Supports iOS version 7.1 or above.

Download package and include library, bundle and header files in project.

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

YalgaarClient *objYalgaarClient  = [[YalgaarClient alloc] init];
objYalgaarClient.delegate = delegate_object;

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

(void)connectWithClientKey:(NSString*)clientKey IsSecure:(BOOL)isSecure Error:(NSError**)error;
(void)connectWithClientKey:(NSString*)clientKey IsSecure:(BOOL)isSecure WithUUID:(NSString*)uuid Error:(NSError**)error;
(void)connectWithClientKey:(NSString*)clientKey IsSecure:(BOOL)isSecure AESSecretKey:(NSString*)aesKey AESKeyType:(AESKeyType)keyType Error:(NSError**)error;
(void)connectWithClientKey:(NSString*)clientKey IsSecure:(BOOL)isSecure WithUUID:(NSString*)uuid AESSecretKey:(NSString*)aesKey AESKeyType:(AESKeyType)keyType Error:(NSError**)error;

Parameter:

  • clientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: NSString
  • 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: NSString
  • aesKey
    • Description: AESSecreteKey to transmit data over network using encryption.
    • DataType: NSString
  • 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
      • (void) connectionError:(NSError *)error; called when any network error occurred during connect to Yalgaar.
      • (void) connectionAlreadyEstablished:(NSObject*)yalgaarClient; called when connection already exist on this object.
      • (void) didConnected; called when connection done successfully.


2 Publish Message

To publish message, use following method.

(void)publishWithChannel:(NSString*)channel Message:(NSString*)message Error:(NSError**)error;

Parameter:

  • channel
    • Description : Channel name on which data will be published.
    • DataType : NSString
  • message
    • Description : Data to be send.
    • DataType : NSString
  • 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.
      • (void) publishStatus:(BOOL)status Error:(NSError *)error;


3 Subscribe Message

To subscribe message, use following method.

(void)subscribeWithChannel:(NSString*)channel Error:(NSError**)error;
(void)subscribeWithChannels:(NSArray*)channels Error:(NSError**)error;

Parameter:

  • channel
    • Description: Subscription Channel in form of string. Channel name is CASE SENSITIVE.
    • DataType: NSString
  • channels
    • Description: Array having one or more subscription Channels in form of string. Channel name is CASE SENSITIVE.
    • DataType: NSArray
  • 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.
      • (void) dataReceivedForSubscription:(NSString *)data OnChannels:(NSArray *)Channels; called when receive data (in form of string).
      • (void) didSubscribed; called when successfully subscription of channel(s).
      • (void) subscribeError:(NSError *)error; called with error code if any error occurred during subscription.


4 Unsubscribe Message

To unsubscribe message,use following method.

(void)unsubscribeWithChannel:(NSString*)channel Error:(NSError**)error;
(void)unsubscribeWithChannels:(NSArray*)channels Error:(NSError**)error;

Parameter:

  • channel
    • Description: Unsubscription Channel in form of string. Channel name is CASE SENSITIVE.
    • DataType: NSString
  • channels
    • Description: Array having one or more unsubscription Channels in form of string. Channel name is CASE SENSITIVE.
    • DataType: NSArray
  • 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
      • (void) 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).

(void) dataReceivedOfPresenceForAction:(PresenceAction)action OnChannel:(NSString *)channel UUID:(NSString*)uuid DateTime:(NSDate*)dateTime;

Parameter:

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


6 Get User List

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

(void)getUUIDListForChannel:(NSString*)channel Error:(NSError**)error;

Parameter:

  • channel
    • Description: Name of Channel that is consumed by user.
    • DataType: NSString
  • 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.
      • (void) dataReceivedWithUUID:(NSArray*)arrUUID ForChannel:(NSString*)channel; called in response of above function which contains list of user along with its Channel name.
      • (void) getUUIDListChannelListError:(NSError *)error; called when any error occur.


7 Get Channel List

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

(void)getChannelListForUUID:(NSString*)uuid Error:(NSError**)error;

Parameter:

  • uuid
    • Description: UUID of which user need to get consumed Channels.
    • DataType: NSString
  • 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.
      • (void) dataReceivedWithChannels:(NSArray*)arrChannels ForUUID:(NSString*)uuid; called in response of above function which contains list of Channels along with its UUID.
      • (void) getUUIDListChannelListError:(NSError *)error; called when any error occur.


8 Get Message History

To get the already published messages, use following method.

(void)messageHistoryWithChannel:(NSString*)channel Count:(int)messageCount Error:(NSError**)error;

Parameter:

  • channel
    • Description : Channel name from which messages will be fetched.
    • DataType : NSString
  • 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.
      • (void) dataReceivedForMessageHistroy:(NSArray*)data; called in response of above function which contains array of history data.
      • (void) messageHistoryStatus:(BOOL)status Error:(NSError *)error; called when any error occur.


9 Disconnect

To disconnect connection with Yalgaar Client, use following method.

(void)disconnect;

Parameter:

  • Response Delegates
    • (void) 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 "YalgaarClient.h"
@interface ViewController : UIViewController <YalgaarClientDelegate>{
	YalgaarClient *objYalgaarClient;
}
@end

Below is implementation file ViewController.m

@implementation ViewController
- (void)viewDidLoad {
    ...
    objYalgaarClient = [[YalgaarClient alloc] init];
    objYalgaarClient.delegate = self;
    
    NSError* errorClientIDValidation = nil;
    [objYalgaarClient connectWithClientKey:@"ClientKey" IsSecure: YES Error:&errorClientIDValidation];
	if(errorClientIDValidation != nil){
        NSLog(@"Connection Error: %ld, %@",  (long)errorClientIDValidation.code, errorClientIDValidation.userInfo);
    }

    NSError* errorSub = nil;
    [objYalgaarClient subscribeWithChannel:@"YourChannel" Error:&errorSub];
    if(errorSub != nil){
        NSLog(@"Subscribe Error: %ld, %@",  (long)errorSub.code, errorSub.userInfo);        
    }

    NSError* errorPubData = nil;
    [objYalgaarClient publishWithChannel:@"YourChannel" Message:@"This is iOS Objective C SDK Example" Error:&errorPubData];
    if(errorPubData != nil){
        NSLog(@"Publish Error: %ld, %@", (long)errorPubData.code, errorPubData.userInfo);
    }

    [objYalgaarClient disconnect];
    ...
}
#pragma YalgaarClient delegate methods
...
- (void) dataReceivedForSubscription:(NSString *)data OnChannels:(NSArray *)channels {
    NSLog(@"Data received: %@", data);
}
...

@end