Skip to content

Commit 2b46715

Browse files
authored
Adding help center support for iOS
1 parent 0e59879 commit 2b46715

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

ios/RNZendeskChat.m

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ @implementation RNZendeskChat
5656
});
5757
}
5858

59+
RCT_EXPORT_METHOD(showHelpCenter:(NSDictionary *)options) {
60+
[self setVisitorInfo:options];
61+
dispatch_sync(dispatch_get_main_queue(), ^{
62+
[self showHelpCenterFunction:options];
63+
});
64+
}
65+
5966
RCT_EXPORT_METHOD(setUserIdentity: (NSDictionary *)user) {
6067
if (user[@"token"]) {
6168
id<ZDKObjCIdentity> userIdentity = [[ZDKObjCJwt alloc] initWithToken:user[@"token"]];
@@ -88,6 +95,38 @@ - (UIColor *)colorFromHexString:(NSString *)hexString {
8895
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
8996
}
9097

98+
- (void) showHelpCenterFunction:(NSDictionary *)options {
99+
[ZDKCoreLogger setEnabled:YES];
100+
[ZDKCoreLogger setLogLevel:ZDKLogLevelDebug];
101+
NSError *error = nil;
102+
ZDKChatEngine *chatEngine = [ZDKChatEngine engineAndReturnError:&error];
103+
ZDKSupportEngine *supportEngine = [ZDKSupportEngine engineAndReturnError:&error];
104+
NSArray *engines = @[];
105+
ZDKMessagingConfiguration *messagingConfiguration = [ZDKMessagingConfiguration new];
106+
NSString *botName = @"ChatBot";
107+
if (options[@"botName"]) {
108+
botName = options[@"botName"];
109+
}
110+
if (options[@"withChat"]) {
111+
engines = @[(id <ZDKEngine>) [ZDKChatEngine engineAndReturnError:&error], (id <ZDKEngine>) supportEngine];
112+
}
113+
ZDKHelpCenterUiConfiguration* helpCenterUiConfig = [ZDKHelpCenterUiConfiguration new];
114+
UIViewController* controller = [ZDKHelpCenterUi buildHelpCenterOverviewUiWithConfigs: @[helpCenterUiConfig]];
115+
controller.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @"Close"
116+
style: UIBarButtonItemStylePlain
117+
target: self
118+
action: @selector(chatClosedClicked)];
119+
120+
121+
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
122+
while (topController.presentedViewController) {
123+
topController = topController.presentedViewController;
124+
}
125+
126+
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: controller];
127+
[topController presentViewController:navControl animated:YES completion:nil];
128+
}
129+
91130
- (void) startChatFunction:(NSDictionary *)options {
92131
[ZDKCommonTheme currentTheme].primaryColor = [self colorFromHexString:options[@"color"]];
93132

@@ -111,8 +150,8 @@ - (void) startChatFunction:(NSDictionary *)options {
111150
} else {
112151
engines = @[
113152
(id <ZDKEngine>) [ZDKAnswerBotEngine engineAndReturnError:&error],
114-
(id <ZDKEngine>) [ZDKSupportEngine engineAndReturnError:&error],
115153
(id <ZDKEngine>) [ZDKChatEngine engineAndReturnError:&error],
154+
(id <ZDKEngine>) [ZDKSupportEngine engineAndReturnError:&error],
116155
];
117156
}
118157

0 commit comments

Comments
 (0)