Demo application is included in the Example
folder. To run it, clone the repo, and run pod install
from the Example directory first.
KeyReplySDK Demo
To install KeyReplyView using CocoaPods, add the following line to your Podfile
:
pod 'KeyReply'
You can also add this project:
- as git submodule
- simply download and copy source files to your project
- Xcode 8.0 or later
- iOS 11.0 or later
KeyReplySDK can be added to your view controller via Interface Builder:
- Drop a regular UIView to your view controller
- Set its custom class as
KEYKeyReplyView
class - Hook it up to an IBOutlet in your view controller code
- Perform intialization step detailed below
KeyReplySDK can be initialize programmatically like regular UIView:
CGRect chatFrame = CGRectMake(0, 0, 320, 480);
KEYKeyReplyView * keyReplyView = [[KEYKeyReplyView alloc] initWithFrame:chatFrame];
[self.view addSubview:keyReplyView];
[keyReplyView reload];
To use KeyReplySDK, you will need a SERVER_URL to retrieve each respective bot. Please obtain your own SERVER_URL from KeyReply representative directly.
KeyReplySDK will not automatically load its content. It is necessary to call reload
function whenever you want to start using it. Normally it is done in viewDidLoad
function, after all customisations options are provided.
[*self*.chatView setServerSetting:@"SERVER_URL"];
[keyReplyView reload];
By default, KeyReplySDK will show expanded UI on load. This can be disabled by:
keyReplyView.autoOpenOnStart = NO;
[keyReplyView reload];
All customization of appearance are to be done via KeyReply's web console.
[keyReplyView setServerSetting:@"SERVER_URL"];
[keyReplyView setEnvUrl:@"ENV_URL"];
User settings must be of type NSMutableDictionary
. For example:
NSMutableDictionary * userDict = [[NSMutableDictionary alloc] init];
[userDict setValue:@"bot1" forKey:@"name"];
[userDict setValue:@"123" forKey:@"id"];
[keyReplyView setUserSetting:(NSMutableDictionary)];
This method is to set property appTokenConfigured in the settings, For example:
[keyReplyView enableAppTokenConfiguredInSetting];
[keyReplyView openChatWindow];
[keyReplyView closeChatWindow];
[keyReplyView toggleChatWindow];
Have a selector function ready, copy and change the frame parameters accordingly:
- (void)chatWindowResize:(NSString *)toggle{
if([toggle isEqualToString:@"true"]) {
self.chatView.frame = self.chatViewFrame;
}else {
CGRect newFrame = CGRectMake(x,y,width,height);
self.chatView.frame = newFrame;
}
}
call this method in viewDidLoad method, like so:
[self.chatView setChatWindowResizeFunc:@selector(chatWindowResize:) fromObject:self];
This function will be called inside openChatWindow and closeChatWindow functions
[self.chatView setGenerateJWTFunc:@selector(generateJWTFunc:) fromObject:self];
This function will be called when JWT token passed in is invalid
Take in JWT token as a NSSTRING
.
[keyReplyView setInitWithJWT:(JWTToken)];
Chat message can be sent via KeyReplySDK UI or done programmatically as followed:
[keyReplyView sendMessage:@"Hello world!"];