initialize

Android
iOS

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

ParameterDescriptionEtc.
applicationApp application instance.
attachViewoptional

Flag that determines whether to attach channel button and pop-up to all activities.
Set to false to disable the provided view.

default true
Android only
public class MyApp extends MultiDexApplication {
  @Override
  public void onCreate() {
    super.onCreate();
    
    ChannelIO.initialize(this);
  }
}


// to disable attaching channel button and popup
public class MyApp extends MultiDexApplication {
  @Override
  public void onCreate() {
    super.onCreate();
    
    ChannelIO.initialize(this, false);
  }
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  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

iOS

return UIWindow

ParameterDescription
UIWindowScene
// SceneDelegate.swift

var channelWindow: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  guard let windowScene = (scene as? UIWindowScene) else { return }
  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

iOS

Set delegate to receive events by ChannelIO

ChannelIO.delegate = self
ChannelIO.delegate = self;

setListener

Android

Attach listener to receive events from ChannelIO

ParameterDescription
listenerAn event listener. See Listener / Delegate
public class MyApp extends MultiDexApplication, ChannelPluginListener {
  @Override
  public void onCreate() {
    super.onCreate();
    
    // some codes
    
    ChannelIO.setListener(this);
  }
}

clearListener

Android

Clear listener to stop receiving events.

ChannelIO.clearListener();

boot

Android
iOS

Starts ChannelIO. You may call this method anywhere you want, but be sure that features offered by Channel will only work after it is called. For more details, see document about lifecycle.

ParameterDescription
bootConfigBootConfig object to configure plugin key, user profiles and more.

See BootConfig for more details.
bootCallbackoptional

Callback that is invoked when the boot request is processed. If you need to do some work depending on the boot result, this callback is the place for you to work with.

See BootConfig for more details.

🚧

boot is asynchronous

Booting is a non-blocking operation which allows next line of a code to run immediately. That means, booting may not have finished when the boot method is returned. If your code depends on the boot result, use callback parameter.

BootConfig bootConfig = BootConfig.create(YOUR_PLUGIN_KEY);

ChannelIO.boot(bootConfig, new BootCallback() {
  @Override
  public void onComplete(BootStatus bootStatus, @Nullable User user) {
    if (bootStatus == BootStatus.SUCCESS && user != null) {
      // success
    } else {
      // show failed reason from bootStatus
    }
  }
});
let bootConfig = BootConfig(pluginKey: YOUR_PLUGIN_KEY)

ChannelIO.boot(with: bootConfig) { (completion, user) in
	if completion == .success, let user = user {
		// success
	} else {
		// show failed reason from bootStatus
	}
}
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
  }
}];
const config = {
  "pluginKey": YOUR_PLUGIN_KEY,
  "memberId": MEMBER_ID,
  "memberHash": MEMBER_HASH,
  "profile": {
    "name": NAME,
    "email": EMAIL,
    "mobileNumber": "+~~~",
    "avatarUrl": AVATAR_URL,
    OTHER_KEY: OTHER_VALUE,
  },
  "language": LANGUAGE, // "en", "ko", "jp"
  "unsubscribeEmail": BOOLEAN,
  "unsubscribeTexting": BOOLEAN,
  "trackDefaultEvent": BOOLEAN,
  "hidePopup": BOOLEAN,
  "channelButtonOption": {
    "xMargin": 16,
    "yMargin": 16,
    "position": POSITION,  // "left", "right"
  },
}

ChannelIO.boot(config).then((result) => {
  // result.status
  // result.user
})

sleep

Android
iOS

Set ChannelIO only can receive push notification and track

About life cycle, See About life cycle

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

shutdown

Android
iOS

Stop interaction with ChannelIO
After calling shutdown, All of actions are not possible until boot is called.

About life cycle, See About life cycle

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

showChannelButton

Android
iOS

Show channel button globally. It depend on boot state.

ChannelIO.showChannelButton();

// not shown
ChannelIO.boot(bootConfig, (bootStatus, user) -> {
  if (bootStatus == BootStatus.SUCCESS) {
    // shown
    // You can call it here instead of above.
  } else {
    // not shown
  }
});
ChannelIO.showChannelButton()

// not shown
ChannelIO.boot(with: bootConfig) { (completion, user) in
  if completion == .success, let user = user {
    // shown
    // You can call it here instead of above.
  } else {
    // not shown
  }
}
[ChannelIO showChannelButton];
  
// not shown
[ChannelIO bootWith:bootConfig completion:^(BootStatus status, User *user) {
  if (status == BootStatusSuccess && user != nil) {
    // shown
    // You can call it here instead of above.
  } else {
    // not shown
  }
}];
ChannelIO.showChannelButton();

hideChannelButton

Android
iOS

Hide channel button globally. It depend on boot state.

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

showMessenger

Android
iOS

Open ChannelIO Messenger UI. It same with clicking default channel button. It depend on boot state.

Android needs activity instance

ParameterDescriptionEtc
activityActivity instance that based on Interaction UIAndroid only
ChannelIO.showMessenger(activity);

// not shown
ChannelIO.boot(bootConfig, (bootStatus, user) -> {
  if (bootStatus == BootStatus.SUCCESS) {
    // shown
    // You can call it here instead of above.
  } else {
    // not shown
  }
});
ChannelIO.showMessenger()

// not shown
ChannelIO.boot(with: bootConfig) { (completion, user) in
  if completion == .success, let user = user {
    // shown
    // You can call it here instead of above.
  } else {
    // not shown
  }
}
[ChannelIO showMessenger]
  
// not shown
[ChannelIO bootWith:bootConfig completion:^(BootStatus status, User *user) {
  if (status == BootStatusSuccess && user != nil) {
    // shown
    // You can call it here instead of above.
  } else {
    // not shown
  }
}];
ChannelIO.showMessenger();

hideMessenger

Android
iOS

Close ChannelIO interaction UI when it is opened.
This is the same operation as pressing close button in interaction UI.

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

openChat

Android
iOS

Open chat directly. See more case below.

ParameterDescriptionEtc.
activityActivity instance that based on Interaction UIAndroid only
chatIdChat id to open directly. If chat id is invalid, open lounge.
If chat id is null, open chat with parameter message. See message` parameter.
messagePreset text message when open empty user chat.
This parameter is valid when the chat id is null.

* when null, open empty chat like click start new chat button in lounge.
// Open chat id is '123'
ChannelIO.openChat(activity, "123", null);

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

// Open new chat like click start new chat in lounge
ChannelIO.openChat(activity, null, null);

// Open new chat with "123" in input box. 
// If support bot is enabled, open support bot instead.
ChannelIO.openChat(activity, null, "123");
// 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"]
// Open chat id is '123'
ChannelIO.openChat("123", null);

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

// Open new chat like click start new chat in lounge
ChannelIO.openChat(null, null);

// Open new chat with "123" in input box. 
// If support bot is enabled, open support bot instead.
ChannelIO.openChat(null, "123");

track

Android
iOS

Add event for current user

SDK version, top activity name, screen size is default reserved.
You also call this method in sleep mode

ParamterDescription
eventNameEvent name

max length is 30
propertiesoptional

Event properties.
// Only send event name
ChannelIO.track(EVENT_NAME);

// Event with properties
Map<String, Object> eventProperties = new HashMap<>();
eventProperties.put(PROPERTY_KEY_1, STRING_VALUE);
eventProperties.put(PROPERTY_KEY_2, INT_VALUE);

ChannelIO.track(EVENT_WITH_PROPERTIES_NAME, eventProperties);
// 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];
// Only send event name
ChannelIO.track(EVENT_NAME);

// Send event with properties
ChannelIO.track(
  EVENT_NAME, 
  { 
    PROPERTY_KEY_1: STRING_VALUE, 
    PROPERTY_KEY_2: INT_VALUE
  }
);

updateUser

Android
iOS

Update user.

There has a simple rules.

ParameterDescription
userDataUser data to be updated.

See UserData
callbackCallback that informs you of the result of the API and updated user data.

See UserUpdateCallback

🚧

'UpdateUser' function has some different property from 'Boot' function.

Please check UserData

Map<String, Object> profileMap = new HashMap<>();

// name
profileMap.put("name", USER_NAME);

// mobileNumber
profileMap.put("mobileNumber", "+~~~");

// email
profileMap.put("email", EMAIL);

// avatar url
profileMap.put("avatarUrl", AVATAR_URL);

// other
profileMap.put(OTHER_KEY, OTHER_VALUE);

UserData userData = new UserData.Builder()
    .setLanguage(Language.ENGLISH)
    .setProfileMap(profileMap)
    .build();

ChannelIO.updateUser(userData, (e, user) -> {
  if (e == null && user != null) {
    // success, result data is user
  } else if (e != null) {
    // error, see e
  }
});
var profile: [String:Any] = [:]

// name
profile["name"] = USER_NAME
  
// mobileNumber
profile["mobileNumber"] = "+~~~"
  
// email
profile["email"] = EMAIL
  
// avatar url
profile["avatarUrl"] = AVATAR_URL
  
// other
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 {
    // success, result data is user
  } else if let error = error {
    // error, see 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
  }
}];
const user = {
  "language": LANGUAGE, // "ko", "jp", "en"
  "tags": ["1", "2", "3"],
  "profile": {
    "name": NAME,
    "email": EMAIL,
    "mobileNumber": '+~~~',
    "avatarUrl": AVATAR_URL,
    OTHER_KEY: OTHER_VALUE,
  },
  "profileOnce": {
  },
  "unsubscribed": BOOLEAN,
};
ChannelIO.updateUser(user).then((result) => {
  // result.error
  // result.user
});

addTags

Android
iOS

Add tags to user.

Maximum tags size is 10.
A tag already added is ignored.
Tags are Case-insensitive (migrate to lower case)

null, list includes null, empty list, empty item is not allowed

Previous user's tagParameterResult
["a"]["b"]["a", "b"]
null["a", "b"]["a", "b"]
["a", "c"]["a", "b"]["a", "b", "c"]
["a", "b", "c", "d", "e", "f", "g"]["g", "h", "i", "j"]["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
["a", "b", "c", "d", "e", "f", "g"]["g", "h", "i", "j", "k"]error: combined size is 11
ParameterDescription
tagsTags to add
callbackCallback that informs you of the result of the API and updated user data.

See UserUpdateCallback
List<String> testTags = new ArrayList<>();
testTags.add("tag1");
testTags.add("tag2");
testTags.add("tag3");
testTags.add("tag4");

ChannelIO.addTags(testTags, (e, user) -> {
  if (user != null) {
    // success
  } else if (e != null) {
    // check reason
  }
});

// Simply, you can call like this
ChannelIO.addTags("a", "B"); // -> change to "a", "b"
var testTags: [String] = []
testTags.append("tag1")
testTags.append("tag2")
testTags.append("tag3")
testTags.append("tag4")

ChannelIO.addTags(testTags) { (error, user) in
  if let user = user {
    // success
  } else if error = error {
    // check reason
  }
}
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
  }
}];
let tags = ["1", "2", "3"];
ChannelIO.addTags(tags).then((result) => {
  // result.error
  // result.user
});

removeTags

Android
iOS

Remove tags from user.

A tag which not exists is ignored.

null, list includes null, empty list, empty item is not allowed

Previous user's tagParameterResult
["a", "b"]["a"]["b"]
["a"]["c"]["a"]
["a"]["A", "c"]null

thrid case "A" is same as "a"

ParameterDescription
tagsTags to remove
callbackCallback that informs you of the result of the API and updated user data.

See UserUpdateCallback
List<String> testTags = new ArrayList<>();
testTags.add("tag1");
testTags.add("tag2");
testTags.add("tag3");
testTags.add("tag4");

ChannelIO.removeTags(testTags, (e, user) -> {
  if (user != null) {
    // success
  } else if (e != null) {
    // check reason
  }
});

// Simply, you can call like this
ChannelIO.removeTags("A", "B");
var testTags: [String] = []
testTags.append("tag1")
testTags.append("tag2")
testTags.append("tag3")
testTags.append("tag4")

ChannelIO.removeTags(testTags) { (error, user) in
  if let user = user {
    // success
  } else if error = error {
    // check reason
  }
}
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
  }
}];
let tags = ["1", "2"];
ChannelIO.removeTags(tags).then((result) => {
  // result.error
  // result.user
});

setPage

Android
iOS

Channel tracks how the user navigates throughout the app usage and logs an event so that operators can easily diagnose the cause of the problem or plan a marketing strategy. Operators can see `PageView events in the user info tab. The default page name is a name of Activity for Android and ViewController for iOS.

However, if you are using Single Activity Architecture or implementing some custom navigation logics, logging Activity name may not be appropriate. In this case, you may set a custom name for the page using setPage() method. Discover what is page for details.

🚧

Passing null as argument to setPage is not the same with calling resetPage. A setPage(null) call will literally set page name as null.

ParameterDescription
pagePage data to replace default page value
ChannelIO.setPage(page);
ChannelIO.setPage(page)
[ChannelIO setPage:page]
ChannelIO.setPage(page)

resetPage

Android
iOS

Reverts an action of setPage(). Depending on the platform, name of an Activity or ViewController will be used as a page name.

ChannelIO.resetPage();
ChannelIO.resetPage()
[ChannelIO resetPage]
ChannelIO.resetPage()

initPushToken

Android
iOS

Notifies Channel SDK of the FCM push token changes.

ParameterDescription
tokenPush token
// Any projects that implement their own Firebase service should call this method when onNewToken is called.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
  @Override
  public void onNewToken(String refreshedToken) {
    ChannelIO.initPushToken(refreshedToken);
  }
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
	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]
}
import messaging from '@react-native-firebase/messaging';
import {ChannelIO} from 'react-native-channel-plugin';

componentDidMount() {
  this.onRefreshListener = messaging().onTokenRefresh(fcmToken => {
    ChannelIO.initPushToken(fcmToken);
  });
}

componentWillUnmount() {
  this.onRefreshListener();
}

isChannelPushNotification

Android
iOS

Checks if the push payload is targeting on Channel SDK.

ParameterDescription
payload
public class MyFirebaseMessagingService extends FirebaseMessagingService {
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    Map<String, String> messages = remoteMessage.getData();

    // This line
    if (ChannelIO.isChannelPushNotification(messages)) {
      ChannelIO.receivePushNotification(this, messages);
    }
  }
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {  
  @available(iOS 10.0, *)
  func userNotificationCenter(_ center: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    
    // This line
    if ChannelIO.isChannelPushNotification(userInfo) {
      ChannelIO.receivePushNotification(userInfo)
      ChannelIO.storePushNotification(userInfo)
    }
    completionHandler()
  }

	func application(_ application: UIApplication,
	                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
	                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    // This line
    if ChannelIO.isChannelPushNotification(userInfo) {
      ChannelIO.receivePushNotification(userInfo)
      ChannelIO.storePushNotification(userInfo)
    }
    completionHandler()
  }
}
//iOS 10 and above
- (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();
}

//iOS 9 and others
- (void)application:(UIApplication *)application 
didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  // This line
  if ([ChannelIO isChannelNotification:userInfo]) {
    [ChannelIO receivePushNotification:userInfo completion: ^{
      completionHandler(UIBackgroundFetchResultNoData);
    }];
    [ChannelIO storePushNotification: userInfo];
  } else {
    completionHandler(UIBackgroundFetchResultNoData);
  }
}
import messaging from '@react-native-firebase/messaging';
import {ChannelIO} from 'react-native-channel-plugin';

componentDidMount() {
	this.backgroundMessageHandler = messaging().setBackgroundMessageHandler(
	  async (remoteMessage) => {
	    ChannelIO.isChannelPushNotification(remoteMessage.data).then((result) => {
	        if (result) {
	          ChannelIO.receivePushNotification(remoteMessage.data).then((_) => { });
	        } else {
	          // TODO : Your FCM code
	        }
	      },
	    );
	  },
	);
}

componentWillUnmount() {
  this.backgroundMessageHandler();
}

receivePushNotification

Android
iOS

Notifies an event that the user has received the push notification.

+ Android
Show push notification

ParameterDescriptionEtc.
contextBase context for androidAndroid only
payload
public class MyFirebaseMessagingService extends FirebaseMessagingService {
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    Map<String, String> messages = remoteMessage.getData();

    if (ChannelIO.isChannelPushNotification(messages)) {
      // This line
      ChannelIO.receivePushNotification(this, messages);
    }
  }
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {  
  @available(iOS 10.0, *)
  func userNotificationCenter(_ center: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    
    if ChannelIO.isChannelPushNotification(userInfo) {
      // This line
      ChannelIO.receivePushNotification(userInfo)
      ChannelIO.storePushNotification(userInfo)
    }
    completionHandler()
  }

	func application(_ application: UIApplication,
	                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
	                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    if ChannelIO.isChannelPushNotification(userInfo) {
      // This line
      ChannelIO.receivePushNotification(userInfo)
      ChannelIO.storePushNotification(userInfo)
    }
    completionHandler()
  }
}
//iOS 10 and above
- (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();
}

//iOS 9 and others
- (void)application:(UIApplication *)application 
didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  if ([ChannelIO isChannelNotification:userInfo]) {
    // This line
    [ChannelIO receivePushNotification:userInfo completion: ^{
      completionHandler(UIBackgroundFetchResultNoData);
    }];
    [ChannelIO storePushNotification: userInfo]
  } else {
    completionHandler(UIBackgroundFetchResultNoData);
  }
}
import messaging from '@react-native-firebase/messaging';
import {ChannelIO} from 'react-native-channel-plugin';

componentDidMount() {
	this.backgroundMessageHandler = messaging().setBackgroundMessageHandler(
	  async (remoteMessage) => {
	    ChannelIO.isChannelPushNotification(remoteMessage.data).then((result) => {
	        if (result) {
	          ChannelIO.receivePushNotification(remoteMessage.data).then((_) => { });
	        } else {
	          // TODO : Your FCM code
	        }
	      },
	    );
	  },
	);
}

componentWillUnmount() {
  this.backgroundMessageHandler();
}

storePushNotification

iOS

Save push data to device

ParameterDescription
payloadPush notification payload from push messaging service
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {  
  @available(iOS 10.0, *)
  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)
      // This line
      ChannelIO.storePushNotification(userInfo)
    }
    completionHandler()
  }
//iOS 10 and above
- (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

Android
iOS

Checks if the plugin has unhandled push notification. See push notifications for details.

ParameterDescriptionEtc.
activityBase activity to start chatAndroid only
public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    // This line
    if (ChannelIO.hasStoredPushNotification(this)) {
      ChannelIO.openStoredPushNotification(this);
    }
  }
}
class ViewController : UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    
    // This line
    if (ChannelIO.hasStoredPushNotification()) {
      ChannelIO.openStoredPushNotification()
    }
  }
}
@implementation ViewController

- (void)viewDidLoad { 
	[super viewDidLoad]; 
    
  // This line
  if ([ChannelIO hasStoredPushNotification]) {
		[ChannelIO openStoredPushNotification]
  }
}

@end
if (ChannelIO.hasStoredPushNotification()) {
  ChannelIO.openStoredPushNotification();
}

openStoredPushNotification

Android
iOS

Open chat corresponding to the push notification data stored by storePushNotification call.
See push notification for details.

ParameterDescriptionEtc.
activityBase activity to start chatAndroid only
public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (ChannelIO.hasStoredPushNotification(this)) {
      // This line
      ChannelIO.openStoredPushNotification(this);
    }
  }
}
class ViewController : UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    
    if ChannelIO.hasStoredPushNotification() {
      // This line
      ChannelIO.openStoredPushNotification()
    }
  }
}
@implementation ViewController

- (void)viewDidLoad { 
	[super viewDidLoad]; 

  if ([ChannelIO hasStoredPushNotification]) {
    // This line
    [ChannelIO openStoredPushNotification]
  }
}

@end
if (ChannelIO.hasStoredPushNotification()) {
  ChannelIO.openStoredPushNotification();
}

isBooted

Android
iOS

Check if ChannelIO is in booted state.

ChannelIO.isBooted();
ChannelIO.isBooted
ChannelIO.isBooted
ChannelIO.isBooted().then((result) => {
  // boolean
});

setDebugMode

Android
iOS

Set debug mode. Debug logs are shown.

ParameterDescription
flagDebug flag
ChannelIO.setDebug(true);
ChannelIO.setDebugMode(with: true)
[ChannelIO setDebugModeWith:@(YES)]
ChannelIO.setDebugMode(true);

setAppearance

  • 'light', 'dark': use dark/light theme
  • 'system': follow system theme
iOS

Set appearance settings.

ParameterDescriptionEtc.
appearanceSet appearance settings.

default: light

- 'light', 'dark': use dark/light theme
- 'system': follow system theme
iOS Only(> 10.1.0)
ChannelIO.setAppearance(.light)
[ChannelIO setAppearance:AppearanceLight];