-
Notifications
You must be signed in to change notification settings - Fork 0
Channelize API SDK Integration
The following documentation is built to help you with integration of our iOS API SDK into your project.
- Dependencies
- Pod Installation
- Required Files
- App Permission
- Configuring and Connecting
- API references
- Real Time Updates
Requirements Before we begin, please do make sure that
- Your application is built on iOS 9.0 or above.
- Since Channelize SDK as of now only supports Version 9.0 or higher.
- You have Xcode 9.4.1 or later as your IDE to install and run Channelize SDK on iOS.
- Swift 4 / 4.1
To use API SDK you need to install following pods
pod 'MQTTClient', '0.14.0'
pod 'MQTTClient/Websocket'
pod 'Alamofire', '4.7.3'
pod 'AlamofireObjectMapper', '5.1.0'
You need create an .plist file with name as "Channelize-Info.plist" and place following keys
<key>PUBLIC_KEY</key>
<string>xxxx PublicKey xxxx</string>
<key>API_URL</key>
<string>xxxx API URL xxxxx </string>
<key>MQTT_URL</key>
<string>xxxxxxx MQTT URL xxxxxx</string>
Make sure following app permissions are in your app info.plist file
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
- To configure Channelize you need to add the following code in
didFinishLaunchingWithOptions
function of your project'sAppDelegate.swift
file
Channelize.configure()
- You need to Login into Channelize server before using APIs. To login add following code in your app(most preferred on login button action in your app)
Channelize.main.login(username: email, password: password){(user,error) in
guard error == nil else {
return }
//Use User details here
- Connect user to get various event delegate calls(Please connect only logged users)
Channelize.connect()
- Disconnect a user from Channelize server to stop receiving further notifications, messages and event notifications
Channelize.disconnect()
- To logout from Channelize server, please add following code, where you want user to logout
Channelize.main.logout()
Number of Conversations
CHService.main.getRecentChatCount(completion: {(count,error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your Stuff here
})
Get Recent Conversations
- To retrieve a list of all conversations request following API Call
//limit : Number of chats you want to get in one call
//offset : Index of starting chat like 0,30,etc.
CHService.main.getChats(limit: 50, offset: 0, completion: {(conversations,error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
})
Get Conversation With a particular user
- To get conversation with a particular User, make following API request
CHService.main.getChat(with: USER_ID, completion: {(conversation,error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
})
Get Conversation of conversation id
- To get conversation with a particular id, make following API request
CHService.main.getChat(of: CHAT_ID, completion: {(conversation,error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
})
Clearing a Conversation
- To clear a conversation, make following API request using a conversation object.
conversation.clear(){(status, error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
}
Deleting a Conversation
- To delete a conversation, make following API request using a conversation object.
conversation.delete(){(status, error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
}
Get total Number of groups Count
- To get total number of groups, make following API request
CHService.main.getGroupsCount(completion: {(groupsCount) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
})
Get List of Groups
- To get list of groups, make following API request
//limit: Numbers of groups list in one call
//offset: Starting index for groups list call
CHService.main.getGroups(limit: LIMIT, offset: OFFSET, completion: {(conversations,error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
})
Creating Groups
-
CHConversation
objects are created by callingcreateGroup(title:memberIds:imageData:completion)
usingCHService
class. - To create a groups, create following API request Fields are:
-
title
:(String,Required) -> Title of the group -
memberIds
:(Array,Required) -> Groups Members Ids -
imageData
: (Data,Optional) -> Image Data for Group Profile Image -
completion
:(Required, ChatData): Completion handler which return the created object of CHConversation & error if the request failed.
CHService.main.createGroup(title: GROUP_TITLE, memberIds: [MEMBERS_IDS], imageData: IMAGE_DATA, completion: {(conversation,error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
})
Leave a group
- To leave a group, make following API request using conversation object of that group.
conversation.leave(){(status, error) in
guard error == nil else { // Error.
return
}
}
Add Member to a group
- To add a member to the Group make following API request using conversation object of that group.
conversation.addMembers(userIds: [USER_IDS]){(conversation, error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
}
Remove Member from the Group
- To remove members from the group, make following API request using conversation object of that group.
conversation.removeMembers(userIds: [USER_IDS]){(conversation, error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
}
Make a member Admin of the Group
- To make members admin of the group, make following API request using conversation object of that group.
conversation.makeAdmin(userId: USER_ID){(status, error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
}
Updating a group Title
- To update title of the group, make following API request using conversation object of that group.
conversation.changeTitle(title: TITLE_NAME){(conversation, error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
}
Updating Group Profile Photo
- To update a group profile photo, make following API request using conversation object of that group.
conversation.updateProfileImage(data: IMAGE_DATA){(conversation, error) in
if let error = error {
return print(error.localizedDescription)
}
// Do your stuff here
}
Get the list of messages for a conversation
- For getting the total number of messages -
conversation.getMessageCount() {(count, error) in
if let error = error {
return print(error.localizedDescription)
}
//Do your stuff here
}
- Using the
getMessages(limit:Int?, offset:Int?, completion:completion)
call you can retrieve the list of messages which provide an array ofCHMessage
type objects.
conversation.getMessages(limit: DEFAULT_LIMIT, offset: OFFSET) {(messages, error) in
if let error = error {
return print(error.localizedDescription)
}
//Do your stuff here
}
Remove messages
- Using the
deleteMessages(messageIds:[String], completion: completion)
call you can delete messages using their ID's.
conversation.deleteMessages(messageIds:[MESSAGE_ID'S]){(status, error) in
if let error = error {
return print(error.localizedDescription)
}
//Do your stuff here
}
Mark messages as read
- Using the
markAllMessagesAsRead()
call you can delete messages using their ID's.
conversation.markAllMessagesAsRead()
Mark a message as read
- Using the
markAsRead()
call you can mark a message read
message.markAsRead()
Sending Messages
- For Normal Messages
CHMessage
objects are created by callingsendMessage(text:data:fileUrl:type:completion)
using conversation object. The fields are as follows:- text (Optional, String?): text message as String. Add this if you are sending a text message.
- data (Optional, Data?): file as Data if you sending audio,image or video file as Data.
- fileUrl (Optional, URL?): url of the file you are trying to send.
- type (Required, CHMessageType): attachment type of the message. Choose from the enum.
- completion (Required, MessageResult): Completion handler which return the created object of CHMessage & error if the request failed.
conversation.sendMessage(text: MESSAGE_TEXT, data: FILE_DATA, fileUrl: FILE_URL, type:ATTACHMENT_TYPE){
(message, error) in
guard error == nil else { // Error.
return
}
}
- For Quoted Message
CHMessage
objects are created by callingsendQuotedMessage(text:quotedMessage:completion)
using conversation object. The fields are as follows:- text (Required, String): text message as String.
- quotedMessage (Required, [String]): An instance of the message that is being quoted.
- completion (Required, MessageResult): Completion handler which return the created object of CHMessage & error if the request failed.
conversation.sendQuotedMessage(text: MESSAGE_TEXT, quotedMessage: QUOTED_MESSAGE){(message, error) in
guard error == nil else { // Error.
return
}
}
Retrieve a list of all or certain users
- For getting the total number of user you can request the following call -
CHService.main.getUserCount() {(count, error) in
if let error = error {
return print(error.localizedDescription)
}
//Do your stuff here
}
- You can also retrieve a list of group conversations in Channelize application by requesting the following call.
CHService.main.getUsers(limit: defaultLimit, offset: offset){(users, error) in
if let error = error {
return print(error.localizedDescription)
}
//Do your stuff here
}
Retrieve a list of all or certain online users
- You can also retrieve a list of group conversations in Channelize application by requesting the following call.
CHService.main.getOnlineUsers {(onlineUsers, error) in
if let error = error {
return print(error.localizedDescription)
}
//Do your stuff here
}
Retrieve a user using user id
- You can also retrieve a user using it's
user_id
in Channelize application by requesting the following call.
CHService.main.getUser(with: USER_ID) {(user, error) in
if let error = error {
return print(error.localizedDescription)
}
//Do your stuff here
}
Retrieve a list of all or certain blocked users in an application
- You can also retrieve a list of all blocked users in Channelize application by requesting the following call. The method returns a list of User objects which contain information about blocked users.
CHService.main.getBlockedUsers(){ (users, error) in
guard error == nil else { // Error.
return
}
}
Blocking/Unblocking
-
User’s have the ability to block/unblcok other users, allowing them to have a sense of privacy and security around the kinds of people that they interact with. If User A blocks User B:
- User B can not create a conversation with User A & vice versa.
- User B can not send messages to User A & vice versa, if a conversation already exists between the two.
- Note that these rules do not apply to Group Conversations
CHService.main.blockUser(userId: USER_ID){ (status, error) in
guard error == nil else { // Error.
return
}
if status {
// Successfully Blocked
}
}
- To unblock a user using the following code -
CHService.main.unblockUser(userId: USER_ID){ (status, error) in
guard error == nil else { // Error.
return
}
if status {
// Successfully UnBlocked
}
}
- To handle real time Updates using MQTT, please refer to this page https://github.com/ChannelizeIO/Channelize-iOS/wiki/MQTT-Subscriber-Setup-with-Channelize-API-SDK