Welcome to Teamchat SDK’s documentation!

Introduction

Teamchat SDK is a framework for iOS, that helps any third party application to easily integrate with Teamchat messaging service. The SDK provides UI elements to display the groups for a user, and also the chat timeline for any selected group. It also supports few UI configurations such as setting different icons, colors, etc. The following sections describe various features of the SDK, such as authentication, getting groups, displaying groups, and chat timeline of a group.

Interface

Initialization

SDK exposes an object called Teamchat. This object provides an object oriented interface to the SDK. You can initialize by supplying an Application ID provided by Teamchat. This method should be called in application:didFinishLaunchingWithOptions: method of AppDelegate.

The following code demonstrates how to initiate Teamchat:

+(void)initializeWithAppID:(NSString*)appID withCompletionHanlder:(^(BOOL, NSError*))handler
Parameter Type Description
appID String This is an alpha numeric string provided by the Teamchat Server
handler ^(BOOL success,NSError* error) Initialization is successful, the ‘success’ will be TRUE. NSError will convey if any problem was encountered during initialization.

Example:

static const NSString * const APP_ID = @“XXZ”

[Teamchat initializeWithAppID:APP_ID  withCompletionHanlder: ^(BOOL success,  NSError* error)
{
        if( success == TRUE )
        {
                //Success
        }
        else
        {
                //Failure while initializing the Teamchat object.
        }

}

Setting up remote notifications

Device token should be set, to enable push notifications. Use the following API to setup remote notifications and this API should be called in application:didRegisterForRemoteNotificationsWithDeviceToken: method of AppDelegate.

The following code demonstrates how to setup remote notifications:

+ (void)setRemoteNotificationsDeviceToken:(NSString*)deviceToken
Parameter Type Description
deviceToken String A token that identifies the device to APNs.

Example:

[Teamchat setRemoteNotificationsDeviceToken:<deviceToken>];

The push notification certificate name can be set using the following API:

+ (void)setPNEnvironmentID:(NSString*)pnEnvironmentID;
Parameter Type Description
pnEnvironmentID String Push notification certificate name.

Example:

[Teamchat setPNEnvironmentID:<pnEnvironmentID>];

Login

You can login to Teamchat in 2 ways.

1. By setting Authentication code, Email ID, UserID and host URL

Setting Authentication code

Before any other API on Teamchat can be called, you need to pass it the authentication code that you have got from a Teamchat authentication service. You can set the authentication code:

+(void)setAuthenticationCode:(NSString*)authCode
Parameter Type Description
authCode String The authentication code provided by Teamchat service

Example:

static const NSString* const authCode = @”AUTH_CODE”
[Teamchat setAuthenticationCode: authCode]
Setting User Email

Before any other API on Teamchat can be called, you need to pass it the user email that you have got from a Teamchat authentication service. You can set the email:

+(void)setUserEmailID:(NSString*)emailID
Parameter Type Description
emailID String Email ID

Example:

[Teamchat setUserEmailID: emailID]
Setting User ID

Before any other API on Teamchat can be called, you need to pass it the user ID that you have got from a Teamchat authentication service. You can set the user id:

+(void)setUserID:(NSString*)userID
Parameter Type** Description
userID String The user ID

Example:

static const NSString * const userID = @”UserID”
[Teamchat setUserID: userID]
Setting Host URL

You can set the host URL using the following API:

+ (void)setHostURL:(NSString *)hostURL;

Example:

[Teamchat setHostURL:@“<Host URL>”]

2. Teamchat login.

Use the following API to get login view controller.

+(UIViewController*)teamchatLoginViewController:(^(BOOL, NSError*,NSString*))handler
Parameter Type Description
handler ^(BOOL success, NSError* error, NSString* errMsg) If login is successful, ‘success’ will be true. NSError will convey any error if occurred during login.

If you set an email using ‘[Teamchat setUserEmailID: emailID]’, then the login page will have pre-filled email field without editing support.

Example:

UIViewController* controller  = [Teamchat teamchatLoginViewController: ^(BOOL success,  NSError* error, NSString *errMsg)
{
        if( success == TRUE )
        {
                //Success
        }
        else
        {
                //Failure while logging into Teamchat.
        }

}

Use this controller to present wherever it is appropriate in your application.

_images/Login.png

Initializing Teamchat

After all the above mentioned, required parameters are set, or after successful login, this method should be called before any group creation or ViewController creation APIs on Teamchat can be called.

+(void)initWithCompletionHandler:(^(BOOL, NSError*,NSString*))handler
Parameter Type Description
handler ^(BOOL success, NSError* error, NSString* errMsg) Initialization is successfull, ‘success’ will be true. NSError will convey any any problem was encountered during initialization.

Example:

[Teamchat iniWithCompletionHanlder: ^(BOOL success,  NSError* error, NSString *errMsg)
{
        if( success == TRUE )
        {
                //Success
        }
        else
        {
                //Failure while initializing Teamchat.
        }

}];

While this asynchronous API is in progress, your app might want to show some progress indicator to indicate Teamchat is being initialized.

Setting UI configurations

You can set navigation bar title, navigation bar tint color, and the chat browser icon in chat window as well as the icon to indicate rich media in the chat window. If you do not call any of these APIs, then the default values will be used.

+(void)setNavigationTitle:(NSString*)title;

+(void)setNavigationTitleColor:(UIColor*)color;

+(void)setMediaIcon:(UIImage*)iconImage;

+(void)setChatletIcon:(UIImage*)iconImage;

+(void)setTableViewSeparatorColor:(UIColor*)seperatorColor;

Example:

[Teamchat setNavigationTitle:@"My title"];
[Teamchat setNavigationTitleColor:[UIColor greenColor]];
[Teamchat setMediaIcon:[UIImage imageNamed:@"mediaIcon"]];
[Teamchat setChatletIcon:[UIImage imageNamed:@"chatletIcon"]];
[Teamchat setTableViewSeparatorColor:[UIColor blueColor]];

You can customise navigation bar’s left bar button items using the following API:

+ (void)setNavigationItemLeftBarButtonItems:(NSArray *)leftBarButtonItems;
Parameter Type Description
leftBarButtonItems NSArray An array of bar button items that should be set as left bar button items of navigation item.

Example:

UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                                                   target:self action:@selector(addButtonHandler:)];
[Teamchat setNavigationItemLeftBarButtonItems:@[leftBarButtonItem]];

Getting groups/rooms

You can get list of groups using the rooms API.

+(NSArray*)teamchatGroups:(NSError **)error
Parameter Type Description
error NSError** An error object, passed by reference.

Example:

NSError *error;
NSArray *groups =[Teamchat teamchatGroups:&error];

If no error, groups will be an array containing TeamchatGroup objects.

The TeamchatGroup object is a light weight object and has the following simple properties:

groupID The identifier of the group as NSString
name Name of the room

Creating a new group

You can create a new group using the API’s provided in TeamchatGroupCreator class defined in TeamchatGroupController.

Create a new instance of TeamchatGroupCreator:

TeamchatGroupCreator *groupCreator = [TeamchatGroupCreator new];

Setting group name

Use the following API to set a name for the new group:

- (void)setGroupName:(NSString *)groupName;

Note that the group name cannot exceed 20 characters.

Example:

[groupCreator setGroupName:@"<Group name"];

Setting group members

Use the following API to set the members the new group:

- (void)setGroupMembers:(NSArray *)members;
Parameter Type Description
members NSArray An array of TCTeamchatContact objects

The TCTeamchatContact object is a light weight object and has the following simple properties:

profileName Contact display name
email Contact email
phone Contact phone number

Example:

TCTeamchatContact *contact1 = [TCTeamchatContact new];
contact1.profileName = @"<name>”;
contact1.email = @"<contact email>";

TCTeamchatContact *contact2 = [TCTeamchatContact new];
contact2.profileName = @"<name>”;
contact2.phone = @"<contact phone number>";

[groupCreator setGroupMembers:@[contact1, contact 2]];

Setting admin only option

You can enable admin only option, where only the admin can post to the group, using the following API:

- (void)setAdminOnly:(BOOL)adminOnly;

If you do not set this option, then default will be taken as NO and all members can post to the group.

Example:

[groupCreator setAdminOnly:YES];

Hiding member profiles

You can hide member profiles from the group members using the following API:

- (void)setShouldHideMemberProfiles:(BOOL)shouldHideMemberProfiles;

If you do not set this option, then default will be taken as NO and member profiles will not be hidden.

Example:

[groupCreator setShouldHideMemberProfiles:YES];

Creating the group

You can create a new group using the following API:

- (void)createGroupWithCompletionHandler:(^(BOOL success, NSError* error, NSString *msg, TeamchatGroup *createdGroup))handler;

Note that this API should be called only after setting group name and members.

Parameter Type Description
handler ^(BOOL success, NSError* error, NSString* msg, TeamchatGroup* createdGroup)

If group creation was successful, then ‘success’ will be TRUE and createdGroup will have a valid ‘TeamchatGroup’ object.

NSError will convey if any problem was encountered during group creation.

Example:

[groupCreator createGroupWithCompletionHandler:^(BOOL success, NSError *error, NSString *msg, TeamchatGroup *createdGroup) {

    if (success)
    {
        // Group created successfully
    }
    else
    {
        // Error
    }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that the group creation is in progress.

Creating the chat group using group ID

You can get a specific group using this API.

+(TeamchatGroup *)teamchatGroupWithID:(NSString*)groupID error:(NSError**) error
Parameter Type Description
groupID String Group ID
error NSError** An error object, passed by reference.

Example:

NSError *error;
TeamchatGroup *group = [Teamchat teamchatGroupWithID:<groupID> error:&error];

If no error, a valid group will be returned.

Teamchat Group Configuration APIs

Adding members to group

You can add members to a group only if you are the admin of the group.

You can add members to an existing group using the following API:

+ (void)addMembers:(NSArray *)membersToBeAdded toGroup:(TeamchatGroup *)teamchatGroup
                completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
membersToBeAdded NSArray An array of ‘TCTeamchatContact’ objects.
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ to which members are to be added.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If members were added successfully, then ‘success’ will be TRUE.

NSError will convey if any problem was encountered while adding members.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];

TCTeamchatContact *memberToBeAdded = [TCTeamchatContact new];
memberToBeAdded.profileName = @"<Profile name>";
memberToBeAdded.email = @"<email>";

TCTeamchatContact *anotherMemberToBeAdded = [TCTeamchatContact new];
anotherMemberToBeAdded.profileName = @"<Profile name>";
anotherMemberToBeAdded.phone = @"<phone number>";

[TeamchatGroupController addMembers:@[memberToBeAdded, anotherMemberToBeAdded] toGroup:group completion:^(BOOL success, NSError *error, NSString *msg) {

    if (success)
    {
        // Members were added successfully
    }
    else
    {
        // Error
    }
}];

You can also add Teamchat server contacts to a group. You can get the server contacts using the following API:

+ (void)getTeamchatServerContactsWithCompletion:(^(BOOL success, NSError* error, NSArray *fetchedContacts))completionHandler;

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
[Teamchat getTeamchatServerContactsWithCompletion:^(BOOL success, NSError *error, NSArray *fetchedContacts) {
    if (success)
    {
        TCTeamchatContact *firstServerContact = fetchedContacts.firstObject;

        [TeamchatGroupController addMembers:@[firstServerContact] toGroup:group
                                 completion:^(BOOL success, NSError *error, NSString *msg) {
                                     if (success)
                                     {
                                         // Member added successfully
                                     }
                                     else
                                     {
                                         // Error
                                     }
        }];
    }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that members are being added to the group.

Exiting from a group

If you are the admin of the group, the group will be terminated permanently, all members will be removed and all data will be deleted. If you are not the admin of the group, you will just be removed from the group.

Use the following API to exit from a group:

+ (void)exitGroup:(TeamchatGroup *)teamchatGroup
                completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ from which you want to exit.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If exit was successful, then ‘success’ will be TRUE.

NSError will convey if any problem was encountered while exiting group.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
[TeamchatGroupController exitGroup:group completion:^(BOOL success, NSError *error, NSString *msg) {
    if (success)
    {
        // Successfully exited group
    }
    else
    {
        //Error
    }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that exit operation is in progress.

Getting active members of a group

Use the following API to get the list of active members of the group that you are a member of:

+ (NSArray *)getActiveMembersOfGroup:(TeamchatGroup *)teamchatGroup error:(NSError **)error;
Parameter Type Description
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ from which you want to fetch active members.
error NSError** An error object, passed by reference.

An array of ‘TeamchatGroupMember’ objects will be returned if no error.

TeamchatGroupMember is a light weight object with the following simple properties:

memberName Name of the group member
memberID Group member ID
teamchatGroupID ID of the group to which member belongs

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
NSError *error;
NSArray *groupMembers = [TeamchatGroupController getActiveMembersOfGroup:group error:&error];

Getting pending members of a group

Use the following API to get the list of pending members of the group that you are a member of:

+ (void)getPendingMembersOfGroup:(TeamchatGroup *)teamchatGroup
                   completion:(^(BOOL succuss, NSError *error, NSString *msg, NSArray *pendingmembersArray))completionHandler;
Parameter Type Description
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ from which you want to fetch pending members.
completionHandler ^(BOOL success, NSError* error, NSString* msg, NSArray* pendingmembersArray)

If fetch was successful, then ‘success’ will be TRUE and pendingmembersArray will be an array of ‘TeamchatGroupPendingMember’ objects.

NSError will convey if any problem was encountered while fetching pending members.

** TeamchatGroupPendingMember** is a light weight object with the following simple properties:

pendingMemberName Display name of pending member.
pendingMemberID ID of the pending member.
pendingMemberType Type can be either of email or phone.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
NSArray *pendingMembers = [TeamchatGroupController getPendingMembersOfGroup:group
                                    completion:^(BOOL success, NSError *error, NSString *msg, NSArray *pendingmembersArray) {
                                        if (success)
                                        {
                                            // Pending members fetched successfully
                                        }
                                        else
                                        {
                                            // Error
                                        }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that fetch operation is in progress.

Removing an active member from a group

You can remove a member from a group only if you are admin of the group.

Use the following API to remove an active member from a group:

+ (void)removeActiveMember:(TeamchatGroupMember *)groupMember fromGroup:(TeamchatGroup *)teamchatGroup
  completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
groupMember TeamchatGroupMember The group member to be removed.
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ from which you want to remove member.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If member was removed successfully, then ‘success’ will be TRUE.

NSError will convey if any problem was encountered while removing member.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
TeamchatGroupMember *groupMember = [TeamchatGroupMember memberWithID:@"<Member ID" groupID:@"<Group ID>"];

[TeamchatGroupController removeActiveMember:groupMember fromGroup:groupMember
                                 completion:^(BOOL success, NSError *error, NSString *msg) {
                                     if (success)
                                     {
                                         // Member was removed successfully
                                     }
                                     else
                                     {
                                         // Error
                                     }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that remove operation is in progress.

Removing a pending member from a group

You can remove a member from a group only if you are admin of the group.

Use the following API to remove a pending member from a group:

+ (void)removePendingMember:(TeamchatGroupPendingMember *)pendingMember fromGroup:(TeamchatGroup *)teamchatGroup
         completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
pendingMember TeamchatGroupPendingMember The pending member to be removed.
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ from which you want to remove member.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If member was removed successfully, then ‘success’ will be TRUE.

NSError will convey if any problem was encountered while removing member.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];

NSArray *pendingMembers = [TeamchatGroupController getPendingMembersOfGroup:group
                                    completion:^(BOOL success, NSError *error, NSString *msg, NSArray *pendingmembersArray) {
                                        if (success)
                                        {
                                            TeamchatGroupPendingMember *firstPendingMember = pendingmembersArray.firstObject;
                                            [TeamchatGroupController removePendingMember:firstPendingMember fromGroup:group
                                                                    completion:^(BOOL success, NSError *error, NSString *msg) {
                                                                        if (success)
                                                                        {
                                                                            // Pending member removed successfully
                                                                        }
                                                                        else
                                                                        {
                                                                            // Error
                                                                        }
                                                                    }];
                                        }
                                    }];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that remove operation is in progress.

Changing the admin of a group

You can change the admin of a group only if you are admin of the group and after changing the admin, you will no longer be the admin of the group.

Use the following API to change the admin of the group to another active member of the group:

+ (void)changeAdminOfGroup:(TeamchatGroup *)teamchatGroup toGroupMember:(TeamchatGroupMember *)groupMember
        completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ whose admin you want to change.
groupMember TeamchatGroupMember The group member whom you want to change the admin to.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If admin was changed successfully, then ‘success’ will be TRUE.

NSError will convey if any problem was encountered while changing admin.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
TeamchatGroupMember *groupMember = [TeamchatGroupMember memberWithID:@"<member ID>" groupID:@"<group ID>"];

[TeamchatGroupController changeAdminOfGroup:group toGroupMember:groupMember
                        completion:^(BOOL success, NSError *error, NSString *msg) {
                            if (success)
                            {
                                // Admin changed successfully
                            }
                            else
                            {
                                // Error
                            }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that change admin operation is in progress.

Getting the admin of a group

Use the following API to get the admin of the group that you are a member of:

+ (TeamchatGroupMember *)getAdminOfGroup:(TeamchatGroup *)teamchatGroup error:(NSError **)error;
Parameter Type Description
teamchatGroup TeamchatGroup The group whose admin you want to get.
error NSError** An error object, passed by reference.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
NSError *error;

TeamchatGroupMember *adminMember = [TeamchatGroupController getAdminOfGroup:group error:&error];

Changing admin only option of a group

You can change admin only option only if you are the admin of the group.

Use the following API to enable or disable admin only option of the group:

+ (void)setAdminOnlyOption:(BOOL)adminOnly forGroup:(TeamchatGroup *)teamchatGroup
        completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
adminOnly BOOL ‘YES’ to enable admin only option and ‘NO’ to disable admin only option.
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ whose admin only option you want to change.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If admin option was changed successfully, then‘success’ will be TRUE.

NSError will convey if any problem was encountered while changing admin only option.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];

[TeamchatGroupController setAdminOnlyOption:YES forGroup:group
                        completion:^(BOOL success, NSError *error, NSString *msg) {
                            if (success)
                            {
                                // Admin only option changed successfully
                            }
                            else
                            {
                                // Error
                            }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that this operation is in progress.

Hiding member profiles

You can hide or show member profiles only if you are the admin of the group.

Use the following API to show or hide member profiles the group:

+ (void)setMemberProfileHiddenOption:(BOOL)hideMemberProfile forGroup:(TeamchatGroup *)teamchatGroup
        completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
hideMemberProfile BOOL ‘YES’ to hide member profiles and ‘NO’ to show member profiles.
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ whose member profiles you want to show or hide.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If the option was changed successfully, then ‘success’ will be TRUE.

NSError will convey if any problem was encountered while changing this option.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];

[TeamchatGroupController setMemberProfileHiddenOption:YES forGroup:group
                        completion:^(BOOL success, NSError *error, NSString *msg) {
                            if (success)
                            {
                                // Option changed successfully
                            }
                            else
                            {
                                // Error
                            }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that this operation is in progress.

Changing name of the group

You can change the name of the group only if you are the admin of the group.

Use the following API to change the name of the group:

+ (void)changeNameOfGroup:(TeamchatGroup *)teamchatGroup toName:(NSString *)newName
        completion:(^(BOOL success, NSError* error, NSString *msg))completionHandler;
Parameter Type Description
teamchatGroup TeamchatGroup The ‘TeamchatGroup’ whose name you want to change.
newName NSString The new name for the group.
completionHandler ^(BOOL success, NSError* error, NSString* msg)

If the option was changed successfully, then ‘success’ will be TRUE.

NSError will convey if any problem was encountered while changing group name.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];

[TeamchatGroupController changeNameOfGroup:group toName:@"<New name>"
                        completion:^(BOOL success, NSError *error, NSString *msg) {
                            if (success)
                            {
                                // Group name changed successfully
                            }
                            else
                            {
                                // Error
                            }

}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that this operation is in progress.

Clearing messages from a group

You can clear messages of only those groups which you are a member of.

Use the following API to clear all the messages from a group:

+ (BOOL)clearMessagesFromGroup:(TeamchatGroup *)teamchatGroup error:(NSError **)error;
Parameter Type Description
teamchatGroup TeamchatGroup The group whose messages you want to clear.
error NSError** An error object, passed by reference.

This API returns true if messages were cleared successfully. Otherwise error object will convey the error that was occurred.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
NSError *error;

BOOL didClearMessages = [TeamchatGroupController clearMessagesFromGroup:group error:&error];
if (didClearMessages)
{
    // Successfully cleared messages
}
else
{
    // Error
}

Posting a text message to a group

You can post messages to only those groups which you are a member of.

Use the following API to post a text message:

+ (BOOL)postMesage:(NSString *)message toGroup:(TeamchatGroup *)teamchatGroup error:(NSError **)error;
Parameter Type Description
message NSString The text message to be posted.
teamchatGroup TeamchatGroup The group to which you want to post a message.
error NSError** An error object, passed by reference.

This API returns true if message can be posted. Otherwise error object will convey the error that was occurred.

Example:

TeamchatGroup *group = [TeamchatGroup groupWithID:"<groupID>"];
NSError *error;

BOOL canPostMessage = [TeamchatGroupController postMesage:@"<message>" toGroup:group error:&error];

if (canPostMessage)
{
    // Message will be posted
}
else
{
    // Error
}

Showing the chat groups list

Use the following API to get a view controller:

+(UIViewController*)teamchatGroupsViewController;

Example:

UIViewController* controller  = [Teamchat teamchatGroupsViewController];

Use this controller to present wherever it is appropriate in your application.

_images/ChatRooms.png

Note: If this view controller is presented, ‘Cancel’ button will be shown on navigation bar as leftBarButtonItem and tapping on it will dismiss the view controller. If this view controller is pushed, default ‘Back’ button will be shown on navigation bar.

Showing the chat window for a room

Use this API, to load the chat window for a given Teamchat group object.

+(UIViewController*)createTeamchatWindowViewControllerWithGroup:(TeamchatGroup*) group

Example:

UIViewController* controller  = [TeamChat createTeamchatWindowViewControllerWithGroup:<TeamchatGroup>];

Use this controller to present wherever it is appropriate in your application.

_images/ChatWindow.png

Note: If this view controller is presented, ‘Cancel’ button will be shown on navigation bar as leftBarButtonItem and tapping on it will dismiss the view controller. If this view controller is pushed, default ‘Back’ button will be shown on navigation bar.

Getting User profile

Use the following API to get the user profile view controller:

+ (UIViewController *)userProfileViewController;

Example:

UIViewController* controller  = [Teamchat userProfileViewController];

Use this controller to present wherever it is appropriate in your application.

_images/UserProfile.png

Getting Settings View

Use the following API to get the Teamchat settings view:

+ (UIViewController *)settingsViewController;

Example:

UIViewController* controller  = [Teamchat settingsViewController];

Use this controller to present wherever it is appropriate in your application.

_images/Settings.png

Note: If this view controller is presented, ‘Cancel’ button will be shown on navigation bar as leftBarButtonItem and tapping on it will dismiss the view controller. If this view controller is pushed, default ‘Back’ button will be shown on navigation bar.

Getting Public groups View controller

Use the following API to get the Public groups view:

+ (UIViewController *)publicGroupsViewController:(^(TeamchatGroup *selectedGroup))handler;
Parameter Type Description
handler ^(TeamchatGroup * selectedGroup) The public group that was selected

Use this controller to present wherever it is appropriate in your application.

_images/PublicGroups.png

Note: If this view controller is presented, ‘Cancel’ button will be shown on navigation bar as leftBarButtonItem and tapping on it will dismiss the view controller. If this view controller is pushed, default ‘Back’ button will be shown on navigation bar.

Getting user logged out view controller

User session is invalidated when the user is deleted from organisation. SessionState will be set to TCSessionStateInvalidatedOnUserDelete and you can get notified when the user is deleted from organisation by observing to TCActiveSessionIsInvalidatedNotification as follows:

[[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(handleInvalidSession:)
                                         name:TCActiveSessionIsInvalidatedNotification object:nil];

Add this method in the class that should observe for session invalid notification.

When the session is invalidated, you can show logged out view controller. Use the following API to get logged out view:

+ (UIViewController *)userLoggedOutViewController:(void (^)(void))userLoggedOutCompletionHandler;
Parameter Type Description
handler (void (^)(void)) The block to execute after user logs in to Teamchat again. This block has no return value and takes no parameters.

Example:

UIViewController* controller  = [Teamchat userLoggedOutViewController:^{
        // User has logged in to Teamchat
}];

Present this controller when active session is invalidated.

_images/LoggedOut.png

Enabling and showing Passcode view

The different types of passcode views are defined by an enum TCPasscodeViewType, as follows:

  1. TCPasscodeViewTypeEnablePasscode - To show view to enable passcode by setting a new passcode.
  2. TCPasscodeViewTypeDisablePasscode - To show view to disable passcode after entering the current passcode.
  3. TCPasscodeViewTypeUnlock - To show view to enter the passcode and unlock Teamchat.
  4. TCPasscodeViewTypeResetPasscode - To show view to reset the passcode.

Once passcode is enabled, passcode view will be shown if it’s Teamchat view when app enters foreground and you can proceed only after entering the correct passcode.

Getting passcode view controller

Use the following API to get the passcode view for any type described above:

+ (UIViewController *)passcodeViewControllerOfType:(TCPasscodeViewType)passcodeViewType
                        withCompletion:(^(BOOL didProcessPasscode, NSError *error, UIViewController *passcodeViewController))completionHandler;
Parameter Type Description
passcodeViewType TCPasscodeViewType The type of passcode view controller that you want the API to return.
completionHandler ^(BOOL didProcessPasscode, NSError* error, UIViewController* passcodeViewController) This block is called after passcode is enabled or unlocked or reset or disabled and passes the passcode view controller. Dismiss the view controller in this block.

This API returns a viewController to show passcode view of specified type, if no error. Present this view controller wherever appropriate in your app

Example:

UIViewController *passcodeViewController = [Teamchat passcodeViewControllerOfType:TCPasscodeViewTypeEnablePasscode withCompletion:^(BOOL didProcessPasscode, NSError *error, UIViewController *passcodeViewController) {
    if (didProcessPasscode) {
        // Passcode processed successfully
    }
    else
    {
        // Error
    }

    // Dismiss the passcode view controller

    [self dismissViewControllerAnimated:passcodeViewController completion:YES];
}];

if (passcodeViewController)
{
    [self presentViewController:passcodeViewController animated:YES completion:nil];
}

After enabling passcode, the passcode view controller will be shown for all Teamchat views until it’s disabled. But you can also show passcode view for your app’s views by using the option TCPasscodeViewTypeUnlock.

Example:

UIViewController *passcodeViewController = [Teamchat passcodeViewControllerOfType:TCPasscodeViewTypeUnlock withCompletion:^(BOOL didProcessPasscode, NSError *error, UIViewController *passcodeViewController) {
    if (didProcessPasscode) {
        // Passcode processed successfully
    }
    else
    {
        // Error
    }

    // Dismiss the passcode view controller

    [self dismissViewControllerAnimated:passcodeViewController completion:YES];
}];

if (passcodeViewController)
{
    [self presentViewController:passcodeViewController animated:YES completion:nil];
}

Use this controller to present wherever it is appropriate in your application.

_images/PasscodeView.png

You can also reset passcode by passing TCPasscodeViewTypeResetPasscode option to the above API and disable passcode by passing TCPasscodeViewTypeDisablePasscode option to the above API and then presenting the viewController returned by the API.

Checking if passcode is enabled

Use the following API to check if passcode is enabled:

+ (BOOL)isPasscodeEnabled;

This method returns true if passcode is enabled.

Example:

BOOL passcodeEnabled = [Teamchat isPasscodeEnabled];

Checking if passcode view can be presented for a specified option

Use the following API to check if passcode view can be presented for a specified type:

+ (BOOL)canShowPasscodeViewForType:(TCPasscodeViewType)type error:(NSError **)error;
Parameter Type Description
type TCPasscodeViewType The passcode view type that you want to check against.
error NSError ** An error object passed by reference.

This method returns true if passcode view can be presented for the specified type.

Example:

NSError *error;
BOOL canPresentPasscodeView = [Teamchat canShowPasscodeViewForType:<TCPasscodeViewType> error:&error];

Resetting active Teamchat session

Use this API to reset Teamchat session before creating a new session:

- (void)resetTeamchatSession

Example:

[Teamchat resetTeamchatSession];

Checking session state

Teamchat session states are defined by TCSessionState enum and the state could be any one of the enum values which are as follows

  1. TCSessionStateInactive - Teamchat session is inactive
  2. TCSessionStateLoggedIn - User has logged in to Teamchat
  3. TCSessionStateActive - Session is active after initial set up
  4. TCSessionStateInvalidatedOnUserDelete - Session is invalidated when user is deleted from organisation

Use this API to check Teamchat session state:

+ (NSUInteger)sessionState;

Example:

TCSessionState sessionState =  [Teamchat sessionState];

Setting options to display contacts

The different types of contacts that are supported by Teamchat are:

  1. TCShowContactFromLocalAddressBook - Lists the contacts from phone’s address book.
  2. TCShowContactFromServerAddressBook - List the contacts from Teamchat server in users organisation.
  3. TCShowContactFromCustomAddressBook - List the custom contacts from app contact provider as per TCCustomContactProvider.

The TCTeamchatContact object is a light weight object and has the following simple properties:

profileName Contact display name
email Contact email
phone Contact phone number

TCCustomContactProvider is a protocol which provides a method that should return an array of TCTeamchatContact objects. The protocol method is as follows:

- (NSArray*)customAddressBookContacts

This method should be implemented in the class that conforms to TCCustomContactProvider protocol and customAddressBookContactProvider can be set using the following API:

+(void)setCustomAddressBookContactProvider:(id<TCCustomContactProvider>)customAddressBookContactProvider;
Parameter Type Description
customAddressBookContactProvider id <TCCustom ContactProvider> The class that conforms to TCCustom ContactProvider protocol

Example:

[Teamchat setCustomAddressBookContactProvider:<Class that conforms to TCCustomContactProvider>];

You can choose the type of contacts that should be listed in contacts list using the following API:

+ (void)setShowContactOptions:(NSUInteger)showContactOptions
Parameter Type Description
showContactOptions NSUInteger You can pass an option or a combination of options, combined using ‘|’ operator.

Example:

[Teamchat setShowContactOptions:TCShowContactFromLocalAddressBook | TCShowContactFromServerAddressBook | TCShowContactFromCustomAddressBook];

Getting Teamchat server contacts

Use the following API to get the list of Teamchat server contacts:

+ (void)getTeamchatServerContactsWithCompletion:(^(BOOL success, NSError* error, NSArray *fetchedContacts))completionHandler
Parameter Type Description
completionHandler ^(BOOL success, NSError* error, NSArray* fetchedContacts) If contact fetch was successful, then ‘success’ will be TRUE and ‘fetchedContacts’ will be an array of ’TCTeamchatContact’ objects. NSError will convey if any problem was encountered during fetch.

Example:

[Teamchat getTeamchatServerContactsWithCompletion:^(BOOL success, NSError *error, NSArray *fetchedContacts) {
    if (success)
    {
        // Contacts fetched successfully
    }
    else
    {
        // Error
    }
}];

Note: While this asynchronous API is in progress, your app might want to show some progress indicator to indicate that the contacts’ fetch is in progress.

Inviting your contacts to Teamchat

You can invite contacts to Teamchat by creating an array of TeamchatInviteContact objects and passing it to the following API:

+ (void)inviteContactsToTeamchat:(NSArray *)inviteContactsArray compeltionHandler:(^(BOOL, NSError*,NSString*))handler
Parameter Type Description
inviteContactsArray NSArray An array of TeamchatInviteContact objects
handler ^(BOOL success, NSError* error) If invite is successful, the ‘success’ will be TRUE. NSError will convey if any problem was encountered during invite.

Example:

Create TeamchatInviteContact objects as follows:

TeamchatInviteContact *invitee1 = [TeamchatInviteContact new];
invitee1.name = @"John";
invitee1.emailID = @"john.bell@gmail.com";

TeamchatInviteContact *invitee2 = [TeamchatInviteContact new];
invitee2.name = @"Kate";
invitee2.emailID = @"kate.appleseed@gmail.com";

Create an array of TeamchatInviteContact objects.

NSArray *inviteContactsArray = @[invitee1, invitee2];

Note: +(void)initWithCompletionHandler:(^(BOOL, NSError*,NSString*))handler method should be called before calling Invite API.

[Teamchat initWithCompletionHandler:^(BOOL success, NSError* error, NSString *errMsg)
{
        if (success)
        {
                [Teamchat inviteContactsToTeamchat:inviteContactsArray
                compeltionHandler:^(BOOL success, NSError* error, NSString *errMsg)
                {
                        if (success)
                        {
                                // Invite was successful
                        }
                }];
        }
}];

While this asynchronous API is in progress, your app might want to show some progress indicator to indicate Teamchat Invite is in progress.

Getting user info

You can use TeamchatUser class to query about user info like profileName, userEmail, organisation and userID, profileImageURL.

  1. Use the following API to get user’s profile name:

    +(NSString *)profileName;
    

This method returns user’s profile name as String.

Example:

NSString *userName = [TeamchatUser profileName];
  1. Use the following API to get user’s email:

    +(NSString*)userEmail;
    

This method returns the user’s emailID as String.

Example:

NSString *email = [TeamchatUser userEmail];
  1. Use the following API to get user’s organisation:

    + (NSString *)organization;
    

This method returns the user’s organisation as String.

Example:

NSString *organization = [TeamchatUser organization];
  1. Use the following API to get user’s ID:

    + (NSString *)userID;
    

This method returns the user’s ID as String.

Example:

NSString *userID = [TeamchatUser userID];
  1. Use the following API to get user’s profile image URL:

    + (NSString *)profileImageURL;
    

This method returns the user’s profile image URL as String.

Example:

NSString *imageURL = [TeamchatUser profileImageURL];

Tracking Teamchat events

You can track Teamchat events using TeamchatEventTracker class and TeamchatEventTrackerDelegate protocol.

TeamchatEventTrackerDelegate is a protocol which provides a method that provides information about the event name and its properties. The protocol method is as follows:

- (void)eventTracked:(NSString *)eventName withProperties:(NSDictionary *)properties;
Parameter Type Description
eventName NSString Name of a particular event which can be tracked.
properties NSDictionary A dictionary whose keys are the properties associated with the event and values as the value of the the property.

This method should be implemented in the class that conforms to TeamchatEventTrackerDelegate protocol and eventTrackerDelegate can be set using the following API:

-(void)setEventTrackerDelegate:(id<TeamchatEventTrackerDelegate>)eventTrackerDelegate;
Parameter Type Description
eventTrackerDelegate id<TeamchatEvent TrackerDelegate> The class that conforms to TeamchatEventTrackerDelegate protocol.

Example:

[TeamchatEventTrackerDelegate sharedEventTrackerInstance] setEventTrackerDelegate:<Class that conforms to TeamchatEventTrackerDelegate>];

Getting the count of unread messages

Use the following API to get the count of unread messages that were received:

+ (NSInteger)numberOfUnreadMessages;

Example:

NSInteger unreadMsgCount = [Teamchat numberOfUnreadMessages];

Enabling Logs

Use the following API to show the Teamchat logs every time:

+ (void)setLoggingEnabled:(BOOL)loggingEnabled;

Example:

[Teamchat setLoggingEnabled:YES];

Integrating the SDK with your iOS app

  1. Add TeamchatSDK.framework to your project.
  2. Add TeamchatSDK.framework to ‘Embedded Binaries’ field under ‘General’ tab of your project target.
  3. Add TeamchatSDK.framework/TeamChat.momd folder to your project using the “Create folder references” option as shown below.
_images/SetUp.png

Now project navigator will look like:

_images/ProjectNavigator.png

Now you need to initialize the Teamchat object with appID in the AppDelegate method application:didFinishLaunchingWithOptions:.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        [Teamchat initializeWithAppID:<App ID> withCompletionHanlder:^(BOOL success, NSError *error) {
                if (!success)
                {
                        [[[UIAlertView alloc] initWithTitle:@"Failed"
                        message:[error localizedDescription] delegate:nil
                        cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
                }
        }];

        return YES;
}

Enable remote notifications by setting deviceID in the AppDelegate method application:didRegisterForRemoteNotificationsWithDeviceToken:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
        [Teamchat setRemoteNotificationsDeviceToken:deviceTokenString];
}

You can login to Teamchat in two ways:

  1. Set Authentication code, emailID and userID.

    [Teamchat setAuthenticationCode:@"<Auth-code>"];
    [Teamchat setUserEmailID:@"<Email-ID>"];
    [Teamchat setUserID:@"<User-ID>"];
    
  2. Use Teamchat login view controller.

    UIViewController *loginViewController = [Teamchat teamchatLoginViewController:^(BOOL success, NSError *error, NSString *errMsg) {
        if (success)
        {
            // Successful login
        }
        else
        {
            // Login error
        }
    }];
    
    if (loginViewController)
    {
        [self presentViewController:loginViewController animated:YES completion:nil];
    }
    

If you want to configure UI of the Teamchat screens, you can set them as follows:

[Teamchat setNavigationTitle:@"Chats"];
[Teamchat setNavigationTitleColor:[UIColor greenColor]];
[Teamchat setTableViewSeparatorColor:[UIColor redColor]];

To get the chat groups list controller, you can use the following API:

[Teamchat initWithCompletionHandler:^(BOOL success, NSError *error, NSString *errMsg) {
    if (success)
    {
        UIViewController *teamchatGroupsViewController = [Teamchat
                                                          TeamchatGroupsViewController];
        if (teamchatGroupsViewController)
        {
            [self presentViewController:teamchatGroupsViewController animated:YES completion:nil];
        }
        else
        {
            // Error
        }
    }
    else
    {
        // Error
    }
}];

Note: +(void)initWithCompletionHandler:(^(BOOL, NSError*,NSString*))handler method should be called before calling groups list API.

To get the chat window controller, you can use the following API:

[Teamchat initWithCompletionHandler:^(BOOL success, NSError *error, NSString *errMsg) {
    if (success)
    {
        NSError *error;
        TeamchatGroup *group = [Teamchat teamchatGroupWithID:@"<GroupID>" error:&error];

        UIViewController *groupViewController = [Teamchat
                                                 createTeamchatWindowViewControllerWithGroup:group];
        if (groupViewController)
        {
            [self presentViewController:groupViewController animated:YES completion:nil];
        }
        else
        {
            // Error
        }
    }
    else
    {
        // Error
    }
}];

Note: +(void)initWithCompletionHandler:(^(BOOL, NSError*,NSString*))handler method should be called before calling chat window controller API.

To get user profile view controller, you can use the following API:

[Teamchat initWithCompletionHandler:^(BOOL success, NSError *error, NSString *errMsg) {
    if (success)
    {
        UIViewController *userProfileViewController = [Teamchat userProfileViewController];

        if (userProfileViewController)
        {
            [self presentViewController:userProfileViewController animated:YES completion:nil];
        }
        else
        {
            // Error
        }
    }
    else
    {
        // Error
    }
}];

Note: +(void)initWithCompletionHandler:(^(BOOL, NSError*,NSString*))handler method should be called before calling chat window controller API.

To get the public groups view controller, you can use the following API:

[Teamchat initWithCompletionHandler:^(BOOL success, NSError *error, NSString *errMsg) {
    if (success)
    {
        UIViewController *publicGroupsViewController = [Teamchat publicGroupsViewController:^(TeamchatGroup *selectedGroup) {
            if (selectedGroup)
            {
                // Push the selected group's chat window.
                UIViewController *chatWindowViewController = [Teamchat
                                                              createTeamchatWindowViewControllerWithGroup:selectedGroup];
                if (chatWindowViewController)
                {
                    [self.navigationController pushViewController:chatWindowViewController animated:YES];
                }
                else
                {
                    // Error
                }
            }
        }];

        if (publicGroupsViewController)
        {
            [self presentViewController:publicGroupsViewController animated:YES completion:nil];
        }
    }
    else
    {
        // Error
    }
}];

Note: +(void)initWithCompletionHandler:(^(BOOL, NSError*,NSString*))handler method should be called before calling public group API.

To get Teamchat settings view controller, you can use the following API:

[Teamchat initWithCompletionHandler:^(BOOL success, NSError *error, NSString *errMsg) {
    if (success)
    {
        UIViewController *settingsViewController = [Teamchat settingsViewController];

        if (settingsViewController)
        {
            [self presentViewController:settingsViewController animated:YES completion:nil];
        }
        else
        {
            // Error
        }
    }
    else
    {
        // Error
    }
}];

Note: +(void)initWithCompletionHandler:(^(BOOL, NSError*,NSString*))handler method should be called before calling public group API.

Stripping unwanted architectures from SDK binary

You can remove unwanted architectures from Teamchat binary by adding run script in Xcode and the steps are as follows:

  1. Select your application’s Xcode project, then your application target, then select “Build Phases”.
  2. In Xcode menu, select “Editor”, then select “Add Build Phase”, and then click on “Add Run Script Build Phase”.
  3. Disclose the Run Script section in the project editor.

Add the following code to run script:

file_path=${PROJECT_DIR}/TeamchatSDK.framework/TeamchatSDK

# the architectures in the binary
ARCHS=`lipo -info $file_path | sed -e "s/^.*are: //"`

# loop through the architectures
for ARCH in $ARCHS
do
        # remove the architectures which are not valid
        if [[ "$VALID_ARCHS" =~ $ARCH ]];
        then
                lipo -remove $ARCH "$file_path" -output "$file_path"
        fi
done

You should now see the Run Script section in your Build Phase options as shown below:

_images/RunScript.png

Document Version History

This table describes the changes to TeamchatSDK documentation across different versions.

Version Notes
2.0 Added descriptions for the group creation API, and for the group configuration APIs and for enabling and showing passcode view.
1.0 New document that describes the interface to TeamchatSDK and the steps to integrate the SDK with your iOS app.