ChannelIO

This page describes ChannelIO of the ChannelIO iOS SDK (hereafter referred to as SDK).

initialize

parametertyperequireddescription
applicationUIApplicationOan instance of Application.

Initializes ChannelIO. You must call this method once before using any of the other methods of ChannelIO.

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

Required if you use SceneDelegate. intializeWindow Returns a ChannelWindow as a UIWindowScene.
Declare a variable for ChannelIO as a class variable. In the below example, It is channelWindow .

parametertyperequireddescription
windowSceneUIWindowOan instance of UIWindowScene.
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

Delegation object of ChannelIO .

ChannelIO.delegate = self
...
ChannelIO.delegate = self;

boot

Loads the information needed to use the SDK. After a successful boot, you are ready to use the features of SDK.
See these documents Boot, About life cycle for more details.

parametertyperequireddescription
configBootConfigOA boot configuration. You can set the plugin key and position of Channel button, etc.
completion((BootStatus, User?) -> Void)?XA callback from boot . It 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

Disable all functions except receiving system push notifications and track. See About life cycle for more details.

ChannelIO.sleep()
...
[ChannelIO sleep];
...

shutdown

Terminate connection between SDK and Channel. shutdown will discontinue features of the SDK will be discontinued. See About life cycle for more information.

ChannelIO.shutdown()
...
[ChannelIO shutdown];
...

showChannelButton

Displays Channel button on the global screen.

ChannelIO.showChannelButton()
...
[ChannelIO showChannelButton];
...

hideChannelButton

Hide Channel button on the global screen.

ChannelIO.hideChannelButton()
...
[ChannelIO hideChannelButton];
...

showMessenger

Shows the messenger.

ChannelIO.showMessenger()
...
[ChannelIO showMessenger]
...

hideMessenger

Hides the messenger.

ChannelIO.hideMessenger()
...
[ChannelIO hideMessenger];
...

openChat

Opens a Chat. You can open a new one or open an existing chat.

parametertyperequireddescription
chatIdString?XThe id of chat. If chatId is invalid or nil, it will open a newly created chat.
messageString?XA filled message on the message input box. It will be valid when chatId is nil.
// Open chat id is '123'
ChannelIO.openChat(with: "123", message: nil)

// Same as ChannelIO.openChat("123", null);
// When chat id parameter is not null, message parameter is ignored.
ChannelIO.openChat(with: "123", message: "asd")

// Open new chat like click start new chat in lounge
ChannelIO.openChat(with: nil, message: nil)

// Open new chat with "123" in input box. 
// If support bot is enabled, open support bot instead.
ChannelIO.openChat(with: nil, message: "123")
// 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: @"asd"]

// Open new chat like click start new chat in lounge
[ChannelIO openChatWith:nil message: nil]

// Open new chat with "123" in input box. 
// If support bot is enabled, open support bot instead.
[ChannelIO openChatWith:nil message: @"123"]

track

Track the user’s event. See event tracking for more details.

parametertyperequireddescription
eventNameStringOThe name of the event to track. Up to 30 characters.
eventProperty[String: Any]?XAdditional Information of 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 when track is calling. If you call track before setPage, it will not be reflected in the event.

parametertyperequireddescription
pageString?XThe screen name when the track is called.
A setPage(nil) call will literally set the page name as nil.
ChannelIO.setPage(page)
[ChannelIO setPage:page]

resetPage

Resets the name of the screen when track is called. The default value is the name of the ViewController calling the track.

ChannelIO.resetPage()
ChannelIO.resetPage();

updateUser

Updates user information.

parametertyperequireddescription
userData[String: Any?]OInformation of the user to be updated.
completion((Bool, User?) -> Void)?XCallback for the updated user information.
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

Add tags for the user.

parametertyperequireddescription
tags[String]OTags to add.
• The maximum length is 10.
• Tag cannot be duplicated.
• Tag is case-insensitive (Tags are renamed to the lower-case.)
• nil, list including nil, empty list, and an empty string is not allowed.
completion((Error?, User?) -> Void)?XA Callback when the update completes. It returns an error when it fails to add.
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

Remove tags for the user. It Ignores if tags do not exist.

parametertyperequireddescription
tags[String]OTags to be deleted.
nil or empty strings or lists containing them are not allowed.
completion((Error?, User?) -> Void)?XA Callback when the remote tag completes. It returns an error when it fails to remove.
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

Notifies the change of the device token to Channel.

parametertyperequireddescription
deviceTokenDataOThe device token used for remote notification.
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

Checks the received remote notification was from Channel.

parametertyperequireddescription
_[AnyHashable: Any]OThe userInfo object received as 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) {
      ...    
    }
  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 to Channel that the user 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

Store remote notification 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 if there is a stored push notification from 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

Open chat according to the push data stored by receivePushNotifcation .

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

Checks that the SDK is in the boot status.

ChannelIO.isBooted
ChannelIO.isBooted

setDebugMode

Sets SDK’s debug mode. If it sets true, SDK prints log messages in the console.

ChannelIO.setDebugMode(with: true)
[ChannelIO setDebugModeWith:@(YES)]

setAppearance

Sets the appearance of the SDK.

parametertyperequireddescription
appearance[Appearance]((doc:ios-models#appearance)OIf you specify .light and .dark, fix the theme with its properties. If .system, follow the device's system theme. default value is .system.
ChannelIO.setAppearance(.light)
[ChannelIO setAppearance:AppearanceLight];