Authentication - iOS
TapTalk.io Omnichannel SDK provides some essential methods to handle user authentication.

Authenticate User (Optional)

You can authenticate the user that is currently logged in before calling navigateToOneTalk. To do this, you can add an authentication method in the previously created module file. (See Get Started - iOS). We will add a RCT_EXPORT_METHOD named authenticateUser.
You can start by adding an authentication method in AppDelegate.m.
AppDelegate.m
1
@interface AppDelegate () <TapTalkLiveDelegate>
2
3
...
4
5
// Method to authenticate user
6
- (void)authenticateUserWithFullName:(NSString *)fullName
7
email:(NSString *)email
8
success:(void (^)(NSString *message))success
9
error:(void (^)(NSString *message))error {
10
11
[[TapTalkLive sharedInstance] authenticateUserWithFullName:fullName
12
email:email
13
success:^(NSString *message) {
14
success(message);
15
}
16
failure:^(NSError *error) {
17
error(error.localizedDescription);
18
}];
19
}
20
21
@end
Copied!
Parameters fullName: (NSString *) current user's full name email: (NSString *) current user's email address success: (void (^)(NSString *message)) success callback containing a message error: (void (^)(NSString *message)) success callback containing the error message
Then open your AppDelegate.h file and add the following lines to enable the previously created method to be called from another file.
AppDelegate.h
1
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
2
3
...
4
5
- (void)authenticateUserWithFullName:(NSString *)fullName
6
email:(NSString *)email
7
success:(void (^)(NSString *message))success
8
error:(void (^)(NSString *message))error;
9
10
@end
Copied!
Then open the previously created OneTalkStarterModule.m and add a method to bridge the authentication method from AppDelegate to JavaScript.
OneTalkStarterModule.m
1
...
2
3
RCT_EXPORT_METHOD(authenticateUser:(NSString *)fullName
4
email:(NSString *)email
5
successCallback:(RCTResponseSenderBlock)successCallback
6
errorCallback:(RCTResponseSenderBlock)errorCallback)
7
{
8
dispatch_async(dispatch_get_main_queue(), ^{
9
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
10
[appDelegate authenticateUserWithFullName:fullName
11
email:email
12
success:^(NSString *message) {
13
successCallback(@[message]);
14
}
15
failure:^(NSString *message) {
16
errorCallback(@[message]);
17
];
18
});
19
}
Copied!
You can then call the method from JavaScript as such:
1
NativeModules.OneTalkStarter.authenticateUser('USER_NAME',
2
'USER_EMAIL',
3
(successMessage) => {
4
// Successfully authenticated user
5
},
6
(errorMessage) => {
7
// An error occurred during authentication
8
}
9
);
Copied!
After successfully authenticated, user will no longer be required to fill name and email to create a case.

Logout and Clear TapTalkLive Data

You may also add another method when you need to logout and clear all local cached data from Omnichannel SDK. We will name this method clearAllTapLiveData.
Start by adding an authentication method in AppDelegate.m and AppDelegate.h.
AppDelegate.m
1
@interface AppDelegate () <TapTalkLiveDelegate>
2
3
...
4
5
// Method to clear all live chat data
6
- (void)clearAllTapLiveData {
7
[[TapTalkLive sharedInstance] clearAllTapLiveData];
8
}
9
10
@end
Copied!
AppDelegate.h
1
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
2
3
...
4
5
- (void)clearAllTapLiveData;
6
7
@end
Copied!
Then add the method to OneTalkStarterModule.m.
OneTalkStarterModule.m
1
...
2
3
RCT_EXPORT_METHOD(clearAllTapLiveData)
4
{
5
dispatch_async(dispatch_get_main_queue(), ^{
6
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
7
[appDelegate clearAllTapLiveData];
8
});
9
}
Copied!
You can then call the method from JavaScript when needed.
1
NativeModules.OneTalkStarter.clearAllTapLiveData();
Copied!