ChannelIO
initialize
parameter | type | required | description |
---|---|---|---|
application | UIApplication | O | An instance of the Application class. |
Initialize the ChannelIO object. You need to invoke this method at least once before utilizing any of the other ChannelIO
methods.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ChannelIO.initialize(application)
...
return true
}
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[ChannelIO initialize:application];
return YES;
}
initializeWindow
This is required when using SceneDelegate. It returns ChannelWindow
with UIWindowScene.
Declare a class variable for ChannelIO. In the example below, the variable is named channelWindow.
parameter | type | required | description |
---|---|---|---|
windowScene | UIWindow | O | An instance of the UIWindowScene class. |
class SceneDelegate: NSObject, UISceneDelegate {
var channelWindow: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
channelWindow = ChannelIO.initializeWindow(with: windowScene)
}
...
}
}
// SceneDelegate.m
@interface SceneDelegate ()
@property (strong, nonatomic) UIWindow * channelWindow;
@end
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
_channelWindow = [ChannelIO initializeWindowWith:(UIWindowScene *)scene];
}
@end
delegate
The delegation object for ChannelIO.
ChannelIO.delegate = self
...
ChannelIO.delegate = self;
boot
Load the information necessary to use the SDK. After successful Boot
, you are ready to use the features of Channel Talk. For more details, refer to Boot and About life cycle.
parameter | type | required | description |
---|---|---|---|
config | BootConfig | O | A configuration object for Boot . You can set the pluginKey and customize Channel button position, among other options. |
completion | ((BootStatus, User?) -> Void)? | X | A callback from Boot that returns bootStatus and User. |
let bootConfig = BootConfig(pluginKey: YOUR_PLUGIN_KEY)
ChannelIO.boot(with: bootConfig) { (status, user) in
switch status {
case .success:
...
default:
...
}
}
BootConfig *bootConfig = [[BootConfig alloc] init];
[bootConfig setPluginKey:YOUR_PLUGIN_KEY];
[ChannelIO bootWith:bootConfig completion:^(BootStatus status, User *user) {
if (status == BootStatusSuccess && user != nil) {
// success
} else {
// show failed reason from bootStatus
}
}];
sleep
Disables all features except for receiving system push notifications and using the Track
. Real-time functionalities (such as chat, marketing pop-ups, etc.) cannot be used due to the disconnected socket communication with Channel Talk servers. For more detailed guidance, refer to About life cycle.
ChannelIO.sleep()
...
[ChannelIO sleep];
...
shutdown
Disconnects the SDK from the channel. The use of all features of the SDK is suspended. For more detailed guidance, refer to About life cycle.
ChannelIO.shutdown()
...
[ChannelIO shutdown];
...
showChannelButton
Displays the Channel button on the global screen.
ChannelIO.showChannelButton()
...
[ChannelIO showChannelButton];
...
hideChannelButton
Hides the Channel button on the global screen.
ChannelIO.hideChannelButton()
...
[ChannelIO hideChannelButton];
...
showMessenger
Displays the messenger.
ChannelIO.showMessenger()
...
[ChannelIO showMessenger]
...
hideMessenger
Hides the messenger.
ChannelIO.hideMessenger()
...
[ChannelIO hideMessenger];
...
openChat
Opens User chat. If the chatId
exists, open it; otherwise, start a new chat.
parameter | type | required | description |
---|---|---|---|
chatId | String? | X | This is the chat ID. If the chatId is invalid or nil, a new user chat is opened. |
message | String? | X | This is the pre-filled message in the message input field when opening a new chat. It is valid when chatId is nil. |
// Open chat id is '123'
ChannelIO.openChat(with: "123", message: nil)
// Same as ChannelIO.openChat("123", nil);
// When chat id parameter is not null, message parameter is ignored.
ChannelIO.openChat(with: "123", message: "Text here")
// Open new chat like click start new chat in home
ChannelIO.openChat(with: nil, message: nil)
// Open new chat with "Text here" in input box.
// If support bot is enabled, open support bot instead.
ChannelIO.openChat(with: nil, message: "Text here")
// Open chat id is '123'
[ChannelIO openChatWith:@"123" message: nil];
// Same as ChannelIO.openChat("123", null);
// When chat id parameter is not null, message parameter is ignored.
[ChannelIO openChatWith:@"123" message: @"Text here"];
// Open new chat like click start new chat in lounge
[ChannelIO openChatWith:nil message: nil];
// Open new chat with "Text here" in input box.
// If support bot is enabled, open support bot instead.
[ChannelIO openChatWith:nil message: @"Text here"];
openSupportBot deprecated
deprecated
Deprecated. Use
openWorkflow
instead.The support bot is no longer supported and was replaced by workflow. The behavior of
openSupportBot
is the same as that ofopenWorkflow
.message
parameter is ignored.
Opens User chat to run a specific Support bot.
parameter | type | required | description |
---|---|---|---|
supportBotId | String? | X | This is the support bot's ID. If supportBotId is invalid or nil, the chat room is closed. |
message | String? | X | This message will be displayed in the input field after completing the support bot operation. |
// Open Support bot id is '123'
ChannelIO.openSupportBot(with: "123", message: nil)
// Open Support bot id is '123'
// After the Support bot has completed, 'Text here' will be filled on the input box.
ChannelIO.openSupportBot(with: "123", message: "Text here")
// Open Support bot id is '123'
[ChannelIO openSupportBotWith: @"123" message: nil];
// Open Support bot id is '123'
// After the Support bot has completed, 'Text here' will be filled on the input box.
[ChannelIO openSupportBotWith: @"123" message: @"Text Here"];
openWorkflow
Opens a user chat and starts the specified workflow.
openWorkflow
can only be executed when the workflow trigger is set to "When starting a chat via Channel Talk."- If a corresponded workflow with the provided
workflowId
is exists, it will be executed. ifworkflowId
is invalid, an error page is displayed. - If you don't pass
workflowId
, no action is taken.
parameter | type | required | description |
---|---|---|---|
workflowId | String? | X | The ID of workflow to start with. An error page will be shown if such workflow does not exist. |
// Open workflow id "123".
ChannelIO.openWorkflow(with: "123")
[ChannelIO openWorkflowWith: @"123"];
track
Tracks the user's events. For more detailed instructions, refer to the event tracking documentation.
parameter | type | required | description |
---|---|---|---|
eventName | String | O | This is the name of the event to track, with a maximum length of 64 characters. |
eventProperty | [String: Any]? | X | This is additional information about the event. |
// Only send event name
ChannelIO.track(eventName: EVENT_NAME, eventProperty: nil)
// Event with properties
var eventProperties: [String:Any] = [:]
eventProperties[PROPERTY_KEY_1] = STRING_VALUE
eventProperties[PROPERTY_KEY_2] = INT_VALUE
ChannelIO.track(eventName: EVENT_WITH_PROPERTIES_NAME, eventProperty: eventProperties)
// Only send event name
[ChannelIO trackWithEventName:@"EVENT_NAME" eventProperty:nil];
// Event with properties
NSDictionary<NSString *, id> *eventProperties = [NSMutableDictionary dictionary];
[eventProperties setValue:STRING_VALUE forKey:PROPERTY_KEY_1];
[eventProperties setValue:INT_VALUE forKey:PROPERTY_KEY_2];
[ChannelIO trackWithEventName:@"EVENT_WITH_PROPERTIES_NAME" eventProperty:eventProperties];
setPage
Sets the name of the screen along with user chat profile. If track
is called before setPage
, the event will not reflect the page information.
parameter | type | required | description |
---|---|---|---|
page | String? | X | This is the screen name when track is called. When calling .track(nil) , the event's page is set to null . |
profile | [String: Any] | X | The user chat profile value. - When nil is assigned to a specific field within the profile object, only the value of that field is cleared. - The user chat profile value is applied when a user chat is created. |
// Sets the page name.
let page = "SPECIFIC_PAGE_NAME_TO_SET"
ChannelIO.setPage(page)
// You can also fill in profile parameter.
let profile: [String: Any] = [
"additional-userchat-key1": "value1",
"additional-userchat-key2": "value2"
]
ChannelIO.setPage(page, profile: profile)
// Sets the page name.
[ChannelIO setPage:@"SPECIFIC_PAGE_NAME_TO_SET"];
// You can also fill in profile parameter.
NSDictionary<NSString *, id> *profile = [NSMutableDictionary dictionary];
[profile setValue:@"additional-userchat-key1" forKey:@"value1"];
[profile setValue:@"additional-userchat-key2" forKey:@"value2"];
[ChannelIO setPage:@"SPECIFIC_PAGE_NAME_TO_SET" profile:profile];
resetPage
Resets the name of the screen and user chat profile value set by [setPage](doc:ios-channelio#setpage)
. The default page name is the name of the ViewController class that calls track
.
ChannelIO.resetPage()
ChannelIO.resetPage();
hidePopup
Hides the Channel popup on the global screen.
ChannelIO.hidePopup()
[ChannelIO hidePopup];
updateUser
Modifies user information.
parameter | type | required | description |
---|---|---|---|
userData | [String: Any?] | O | This is the user information to be updated. |
completion | ((Bool, User?) -> Void)? | X | This returns the result of user information modification. |
var profile: [String: Any] = [:]
profile[OTHER_KEY] = OTHER_VALUE
let userData = UpdateUserParamBuilder()
.with(language: .english)
.with(profile: profile)
.build()
ChannelIO.updateUser(param: userData) { (error, user) in
if let user = user, error == nil {
...
} else if let error = error {
...
}
}
UpdateUserParamObjcBuilder *builder = [[UpdateUserParamObjcBuilder alloc] init];
// name
[builder withProfileKey:@"name" value:USER_NAME];
// mobileNumber
[builder withProfileKey:@"mobileNumber" value:@"+~~~"];
// email
[builder withProfileKey:@"email" value:EMAIL];
// avatar url
[builder withProfileKey:@"avatarUrl" value:AVATAR_URL];
// other
[builder withProfileKey:@"OTHER_KEY" value:OTHER_VALUE];
[builder withLanguage:LanguageOptionEnglish];
[ChannelIO updateUserWithParam:[builder build] completion:^(NSError * error, User * user) {
if (user != nil && error == nil) {
// success, result data is user
} else (error != nil) {
// error, see error
}
}];
addTags
Adds tags to the user.
parameter | type | required | description |
---|---|---|---|
tags | [String] | O | • The maximum number of tags that can be added is 10. • Tags are stored in lowercase. • Any tags that have already been added will be ignored. • nil, empty strings, or lists containing them are not allowed. |
completion | ((Error?, User?) -> Void)? | X | When adding tags, it returns a User object. If the addition fails, it returns an error. |
var tags: [String] = []
tags.append(TAG_1)
tags.append(TAG_2)
tags.append(TAG_3)
tags.append(TAG_4)
ChannelIO.addTags(tags) { (error, user) in
if let user = user {
...
} else if error = error {
...
}
}
NSMutableArray<NSString *> testTags = [NSMutableArray arrayWithCapacity:4];
[testTags addObject:@"tag1"];
[testTags addObject:@"tag2"];
[testTags addObject:@"tag3"];
[testTags addObject:@"tag4"];
[ChannelIO addTags:testTags completion:^(NSError * error, User * user) {
if user != nil {
// success
} else if error != nil {
// check reason
}
}];
removeTags
Removes tags from the user, ignoring any tags that do not exist.
parameter | type | required | description |
---|---|---|---|
tags | [String] | O | These are the tags to be removed. Null, empty strings, or lists containing them are not allowed. |
completion | ((Error?, User?) -> Void)? | X | When removing tags, it returns a User object. If the removal fails, it returns an error. |
var tags: [String] = []
tags.append(TAG_1)
tags.append(TAG_2)
tags.append(TAG_3)
tags.append(TAG_4)
ChannelIO.removeTags(tags) { (error, user) in
if let user = user {
...
} else if error = error {
...
}
}
NSMutableArray<NSString *> testTags = [NSMutableArray arrayWithCapacity:4];
[testTags addObject:@"tag1"]
[testTags addObject:@"tag2"]
[testTags addObject:@"tag3"]
[testTags addObject:@"tag4"]
[ChannelIO removeTags:testTags completion:^(NSError * error, User * user) {
if user != nil {
// success
} else if error != nil {
// check reason
}
}];
initPushToken
Informs ChannelTalk about updates to the device token.
parameter | type | required | description |
---|---|---|---|
deviceToken | Data | O | This is the device token required for receiving push notifications. |
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
ChannelIO.initPushToken(deviceToken: deviceToken)
...
}
// AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
// AppDelegate.m
@implementation AppDelegate
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[ChannelIO initPushTokenWithDeviceToken:deviceToken.map]
}
isChannelPushNotification
It checks if the push data should be processed by the SDK.
parameter | type | required | description |
---|---|---|---|
_ | [AnyHashable: Any] | O | the userInfo object received through push notifications. |
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if ChannelIO.isChannelPushNotification(userInfo) {
...
}
completionHandler()
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
// This line
if ([ChannelIO isChannelNotification:userInfo]) {
[ChannelIO receivePushNotification:userInfo completion: nil];
[ChannelIO storePushNotification: userInfo];
}
completionHandler();
}
receivePushNotification
Notifies Channel Talk that the user has received a push notification.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if ChannelIO.isChannelPushNotification(userInfo) {
ChannelIO.receivePushNotification(userInfo)
...
}
completionHandler()
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if ([ChannelIO isChannelNotification:userInfo]) {
// This line
[ChannelIO receivePushNotification:userInfo completion: nil];
[ChannelIO storePushNotification: userInfo];
}
completionHandler();
}
storePushNotification
Stores push information on the device.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if ChannelIO.isChannelPushNotification(userInfo) {
ChannelIO.storePushNotification(userInfo)
...
}
completionHandler()
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if ([ChannelIO isChannelNotification:userInfo]) {
[ChannelIO receivePushNotification:userInfo completion: nil];
// This line
[ChannelIO storePushNotification: userInfo];
}
completionHandler();
}
hasStoredPushNotification
Check for any saved push notifications from the Channel.
class ViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if ChannelIO.hasStoredPushNotification() {
...
}
}
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// This line
if ([ChannelIO hasStoredPushNotification]) {
[ChannelIO openStoredPushNotification]
}
}
@end
openStoredPushNotification
Opens a user chat using the stored push information on the device through storePushNotifcation
.
class ViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
ChannelIO.openStoredPushNotification()
...
}
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if ([ChannelIO hasStoredPushNotification]) {
// This line
[ChannelIO openStoredPushNotification]
}
}
@end
isBooted
Verify that the SDK is in a Boot
state.
ChannelIO.isBooted
ChannelIO.isBooted
setDebugMode
Sets the debug mode. If set to true
, log messages will be displayed.
ChannelIO.setDebugMode(with: true)
[ChannelIO setDebugModeWith:@(YES)]
setAppearance
Configures the SDK's theme.
parameter | type | required | description |
---|---|---|---|
appearance | Appearance | O | If specified as .light or .dark , it locks the theme to the respective mode. If specified as .system , it follows the device's system theme. |
ChannelIO.setAppearance(.light)
[ChannelIO setAppearance:AppearanceLight];
applyAppearance deprecated
deprecated
Renamed to
setAppearance
.
Sets the appearance of the SDK.
parameter | type | required | description |
---|---|---|---|
appearance | Appearance | O | If specified as .light or .dark , it locks the theme to the respective mode. If specified as .system , it follows the device's system theme. |
ChannelIO.applyAppearance(.light)
[ChannelIO setAppearance:AppearanceLight];
Updated about 1 month ago