iOS Native
Prerequisites
- iOS version 13 or above
- Xcode 14 or above
Setup
Download the framework
- Open terminal and enter the following command.
curl --user dev.nexus:devNexus -o GipKit-1.1.0.zip https://nexus.gupshup.tech/repository/iOS/GipKit/GipKit-1.1.0.zip- Find the downloaded file and unzip it to get "GipKit.xcframework".
Add the framework
- Drag the framework file into the project folder in Xcode.
- When prompted, select the options as shown below and click Finish.
Link the framework
- Add the framework to the target of the application if not already done.
- Remember to select Embed & Sign under the Embed column.
Grant Permissions
- GipKit requires camera permission to click and upload pictures. It uses Audio permission to convert Speech to Text and record video to upload to the chatbot.
- Add the following keys to Info tab on the project target.
- Privacy - Microphone Usage Description
- Privacy - Camera Usage Description
Import GipKit into ViewModel class
GipKit into ViewModel classimport GipKitGet reference to GipKit in ViewModel class
GipKit in ViewModel classlet gipChat: GipChat = GipChat.sharedSetting the App ID for gipChat
gipChatlet appId: String = "de0fa..."
gipChat.setAppId(appId)Getting the App ID
- Log in to your Gupshup Console account and go to Web under Channels in the navigation bar on the left.
- The App ID can be located in the Embed URL as shown below.
Setting the Developer Key
let devKey: String = "02FD..."
gipChat.setDevKey(devKey)Setting the User Name and User ID
- For logged in users, set the end customer's name and unique ID.
- For anonymous users, set the User Name and User ID to
nil.
let userId: String = "some-user-id"
let userName: String = "some-user-name"
gipChat.setUserId(userId)
gipChat.setUserName(userName)gipChat.setUserId(nil)
gipChat.setUserName(nil)Initializing the SDK
- The
.initializemethod takes a closure which returnstrueif the SDK was initialized successfully. - If the initialization fails, the method returns
false. - Based on this value, appropriate actions can be taken.
gipChat.initialize { initialized in
// if initialized is true, show/enable chat button
// or make appropriate UI state decisions.
}Showing the chat screen
gipChat.show()Listening for error messages
- App can register a delegate and listen for error messages that the SDK can generate.
gipChat.setDelegate(self)- Extend the
ViewModelclass withGipChatDelegateas shown below.
extension ViewModel: GipChatDelegate {
func onError(message: String) {
print(message)
}
}
Updated 6 months ago