Title
Create new category
Edit page index title
Edit category
Edit link
Getting Started
This section help you to start building your integration, so that you can send your first message.
Step 1: Get Your App ID
First of all, you need to create your application (App ID) in dashboard, by accessing Qiscus Chat Dashboard.
You can create more than one App ID within a single account. For further information regarding multiple applications in single account.
Step 2: Install Qiscus Chat SDK
Qiscus Chat SDK requires minimum IOS SDK 9. To integrate your apps with Qiscus, it can be done in 2 steps:
First, you need to add dependency QiscusCore into your Podfile,
If you intent to use Swift 4.2, you can use 0.2.x version, for example:
pod 'QiscusCore', "0.2.17"If you prefer to use Swift 5 you can also this version, for example:
pod 'QiscusCore', "1.0.0"For getting list of versions you can see following link.
Second, you need to pod install from terminal
pod installStep 3: Initialization Qiscus Chat SDK
You need to initiate your App ID for your chat App before carry out to Authentication. Can be implemented in the initial startup. Here is how you can do that:
QiscusCore.setup(WithAppID: appID)The initialization should be called always . The best practise you can put in AppDelegate
Step 4: Authentication to Qiscus
To use Qiscus Chat SDK features, a user firstly need to authenticate to Qiscus Server. This authentication is done by calling loginOrRegister function. This function will retrieve or create user credential based on the unique userID, for example:
QiscusCore.loginOrRegister(userID: userID, userKey: userKey, username: username, extras: extras) { (result, error) in if result != nil { print("success") } else { print("error \(String(describing: error?.message))") }}Where:
userID(string, unique): A User identifier that will be used to identify a user and used whenever another user need to chat with this user. It can be anything, whether is is user's email, your user database index, etc.userKey(string): userKey for authentication purpose, so even if a stranger knows your user Id, he cannot access the user data.username (string): Username for display name inside Chat Room purposes.avatarUrl(string, optional): to display user's avatar, fallback to default avatar if not provided.extras [string:any]: to give additional information (metadata) to user, which consist key-value, for example key:position, and value: engineer
For further detail you might figure out Authentications section.
Step 5: Create a Chat Room
There are three Chat Room types in Qiscus Chat SDK:
- 1-on-1 Chat Room
- Group Chat Room
- Channel Chat Room
In this section, we will tell you about 1-on-1 type. We assume that you already know a targeted user you want to chat with. To start a conversation with your targeted user, it can be done with getRoom method. Qiscus Chat SDK, then, will serve you a new Chat Room, asynchronously. When the room is successfully created, Qiscus Chat SDK will return a Chat Room package through onSuccess listener.
QiscusCore.shared.getRoom(withUser: withUserId, onSuccess: { (room, comments) in print("success")}) { (error) in print(error.message)}Make sure that your targeted user has been registered in Qiscus Chat SDK. Otherwise you will receive error.
Step 6: Send Message
You can send any type of data through Qiscus Chat SDK, in this section let's send a "Hi" message, with type value is text. First you need to construct the CommentModel object, then type the message and the message type. You need to pass roomId and the message value, for example:
let message = CommentModel()message.message = "Hi"message.type = "text"QiscusCore.shared.sendMessage(roomID: roomId, comment: message, onSuccess: { (commentModel) in print("success")}) { (error) in print(error.message)}You can define type and data freely, you can use it for custom UI purposes
Messages can be received by the recipient target through a gotNewMessage event. This event is triggered whenever users send a message.. Here is you will get this event:
//set your delegate in viewWillAppearfunc setRoomDelegage(){ if let room = self.room { room.delegate = self } }//remove your delegate in viewWillDisappearfunc removeRoomDelegate() { if let room = self.room { room.delegate = nil }}extension YourChatViewController : QiscusCoreRoomDelegate { // MARK: Comment Event in Room /// new comment is comming /// /// - Parameters: /// - comment: new comment object func gotNewComment(comment: CommentModel){ } }For further details about message, you can find at Message section and Event handler section
Qiscus Technology