이 문서는 채널톡 iOS SDK(이하 SDK)의 ChannelIO에 대해서 설명합니다.

initialize

매개변수타입필수 여부설명
applicationUIApplicationOApplication 객체입니다.

ChannelIO 객체를 초기화 합니다. SDK의 메서드를 사용하기에 앞서 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

SceneDelegate를 사용하는 경우에 필요합니다. UIWindowScene으로 ChannelWindow를 반환합니다.
클래스 변수로 ChannelIO 용 변수를 선언합니다. 아래 예시에서는 channelWindow 입니다.

매개변수타입필수 여부설명
windowSceneUIWindowOUIWindowScene 객체입니다.
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

ChannelIO에 발생하는 이벤트의 대리자입니다.

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

boot

SDK를 사용하기 위해 필요한 정보를 로드합니다. 부트를 성공한 이후에는 채널톡의 기능을 사용할 준비를 마칩니다.
더 자세한 내용은 부트라이프 사이클을 참고합니다.

매개변수타입필수 여부설명
configBootConfigO부트 설정입니다. 플러그인 키, 채널톡 버튼 위치 등을 설정합니다.
completion((BootStatus, User?) -> Void)?X부트 상태와 유저 정보를 반환합니다.
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

시스템 푸시 알림 수신과 track을 제외한 모든 기능을 비활성화 합니다. 채널톡 서버와의 소켓 통신이 끊기기 때문에 실시간 기능 (채팅, 마케팅 팝업 등) 사용이 불가능합니다. 더 자세한 안내는 라이프 사이클을 참조합니다.

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

shutdown

SDK와 채널과의 연결을 끊습니다. SDK의 모든 기능 사용이 중단됩니다. 더 자세한 안내는 라이프 사이클을 참조합니다.

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

showChannelButton

전역 화면에 채널 버튼을 표시합니다.

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

hideChannelButton

전역 화면에서 채널 버튼을 숨깁니다.

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

showMessenger

메신저를 표시합니다.

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

hideMessenger

메신저를 닫습니다.

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

openChat

유저챗을 엽니다. 새로운 상담을 열거나, 기존에 존재하는 유저챗을 열 수 있습니다.

매개변수타입필수 여부설명
chatIdString?X채팅의 ID 입니다. chatId가 유효하지 않거나, nil 인 경우 새로운 유저챗을 엽니다.
messageString?X새로 채팅을 여는 경우, 메시지 입력창에 미리 입력되어 있는 메시지입니다. chatId가 nil인 경우 유효합니다.
ChannelIO.openChat(with: CHAT_ID, message: MESSAGE)
// 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"]

openSupportBot Deprecated

❗️

해당 API는 Deprecated 되었습니다. openWorkflow를 사용해 주세요.

서포트봇에 대한 지원 종료로 인해 해당 API는 Deprecated 되었으며, 해당 API는 openWorkflow SDK API와 같은 동작을 수행하게 됩니다. message 인자는 무시됩니다.

유저챗을 열어 특정 서포트봇을 실행합니다.

매개변수타입필수 여부설명
supportBotIdString?X서포트봇의 ID 입니다. supportBotId가 유효하지 않거나, nil 인 경우 채팅방을 닫습니다.
messageString?X서포트봇 동작을 완료한 후 입력창에 표시될 메시지입니다.
// Id가 '123'인 서포트봇을 실행합니다.
ChannelIO.openSupportBot(with: "123", message: nil)

// Id가 '123'인 서포트봇을 실행합니다.
// 서포트봇이 완료된 후 메시지 입력창에 '입력 문자'가 입력됩니다.
ChannelIO.openSupportBot(with: "123", message: "입력 문자")
// Id가 '123'인 서포트봇을 실행합니다.
[ChannelIO openSupportBotWith: @"123" message: nil];

// Id가 '123'인 서포트봇을 실행합니다.
// 서포트봇이 완료된 후 메시지 입력창에 '입력 문자'가 입력됩니다.
[ChannelIO openSupportBotWith: @"123" message: @"입력 문자"];

openWorkflow

유저챗을 열며 특정 워크플로우를 실행합니다.

workflowId 인자로 전달한 값에 대응하는 워크플로우가 존재하면 해당 워크플로우가 실행됩니다. 만약 workflowId를 전달하지 않으면 아무런 동작이 수행되지 않습니다. 전달한 workflowId에 대응하는 워크플로우가 존재하지 않으면 에러페이지가 보여집니다.

ChannelIO.openWorkflow(with: "123")
[ChannelIO openWorkflowWith: @"123"];
parametertyperequireddescription
workflowIdString?X워크플로우의 ID입니다.

track

유저의 이벤트를 트래킹합니다. 더 자세한 안내는 이벤트 트래킹 문서를 참조합니다.

매개변수타입필수 여부설명
eventNameStringO트래킹할 이벤트 이름입니다. 최대 30자 입니다.
eventProperty[String: Any]?X이벤트에 대한 추가 정보입니다.
// 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

track 이 호출 될 때의 화면 이름과, 유저챗 프로필을 설정합니다. setPage 보다 먼저 track 을 호출하는 경우 이벤트에 페이지 정보가 반영되지 않습니다.

매개변수타입필수 여부설명
pageString?Xtrack이 호출 될 때의 화면 이름입니다.
.track(nil) 을 호출하는 경우 이벤트의 페이지가 null로 설정됩니다.
profile[String: Any]X유저챗 프로필 값.

- profile 객체 내부의 특정 필드에 nil을 전달할 경우, 해당 필드의 값은 제거되어 적용 됩니다.
- 설정된 유저챗 프로필은 유저챗이 생성될 때 적용됩니다.

resetPage

setPage에 의해 설정된 화면 이름과, 유저챗 프로필을 초기화 합니다. 기본 설정은 track을 호출하는 ViewController의 이름입니다.

ChannelIO.resetPage()
ChannelIO.resetPage();

updateUser

유저 정보를 수정합니다.

매개변수타입필수 여부설명
userData[String: Any?]O수정할 유저 정보입니다.
completion((Bool, User?) -> Void)?X유저 정보 수정 결과를 반환합니다.
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

유저에게 태그를 추가합니다.

매개변수타입필수 여부설명
tags[String]O• 추가할 수 있는 태그의 최대 개수는 10개입니다.
• 태그는 소문자로 변환되어 저장됩니다.
• 이미 추가된 태그는 무시됩니다.
• nil이나 빈 문자열, 혹은 이를 포함하는 리스트는 허용하지 않습니다.
completion((Error?, User?) -> Void)?X태그를 추가한 결과로 User를 반환합니다. 추가에 실패한 경우 에러를 반환합니다.
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

유저의 태그를 제거합니다. 존재하지 않는 태그는 무시합니다.

매개변수타입필수 여부설명
tags[String]O제거할 태그입니다.
• null이나 빈 문자열, 혹은 이를 포함하는 리스트는 허용하지 않습니다.
completion((Error?, User?) -> Void)?X태그를 제거한 결과로 User를 반환합니다. 제거에 실패한 경우 에러를 반환합니다.
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

디바이스 토큰에 대한 변경 사항을 채널톡에 전달합니다.

매개변수타입필수 여부설명
deviceTokenDataO푸시 알림을 받기 위한 deviceToken입니다.
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

SDK가 처리해야 하는 푸시 데이터인지 확인합니다.

매개변수타입필수 여부설명
_[AnyHashable: Any]O푸시 알림으로 받은 userInfo 객체입니다.
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

채널톡에 유저가 푸시 알림을 받았음을 전달합니다.

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

디바이스에 푸시 정보를 저장합니다.

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

디바이스에 저장된 채널 푸시 정보가 있는지 확인합니다.

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

storePushNotification을 통해 디바이스에 저장 된 푸시 정보를 이용하여 유저챗을 엽니다.

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

부트가 된 상태인지 확인합니다.

ChannelIO.isBooted
ChannelIO.isBooted

setDebugMode

디버그 모드를 설정합니다. true로 설정한 경우 로그 메시지가 표시됩니다.

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

setAppearance

SDK의 테마를 설정합니다.

매개변수타입필수 여부설명
appearanceAppearanceO.light와 .dark 로 명시하는 경우 해당 속성으로 테마를 고정합니다. .system 인 경우 기기의 시스템 테마를 따릅니다.
ChannelIO.setAppearance(.light)
[ChannelIO setAppearance:AppearanceLight];

applyAppearance deprecated

❗️

setAppearance으로 변경 되었습니다.

SDK의 테마를 설정합니다.

매개변수타입필수 여부설명
appearanceAppearanceO.light와 .dark 로 명시하는 경우 해당 속성으로 테마를 고정합니다. .system 인 경우 기기의 시스템 테마를 따릅니다.
ChannelIO.applyAppearance(.light)
[ChannelIO setAppearance:AppearanceLight];