pod导入
target 'AIHelpSDK' do
? # Comment the next line if you don't want to use dynamic frameworks
? use_frameworks!
? pod'AIHelpSDK'
? # Pods for AIHelpSDK
end
引入系统库
引入AIhelp文件
#import?<AIHelpSupportSDK/AIHelpSDKConfig.h>
#import?<AIHelpSupportSDK/AIHelpSupportSDK.h>
初始化
注册初始化监听
?? [AIHelpSupportSDK registerAsyncListener:listener eventType:AIHelpEventInitialization];
拉起客服
?AIHelpApiConfigBuilder *builder = [[AIHelpApiConfigBuilder alloc] init];
? ? builder.entranceId=@"E001";
//? ? builder.welcomeMessage = message;
? ? [AIHelpSupportSDK showWithApiConfig:builder.build];
未读消息监听
[AIHelpSupportSDK fetchUnreadMessageCount];
? ? [AIHelpSupportSDK registerAsyncListener:listener eventType:AIHelpEventMessageArrival];
监听方法,根据AIHelp反回的eventType类型判断是初始化还是未读消息数量
voidlistener(constchar*eventData,void(*acknowledge)(constchar*ackData)) {
? ? // 将char类型转换为NSString
? ? NSString*nsString = [[NSStringalloc]initWithBytes:eventDatalength:strlen(eventData)encoding:NSUTF8StringEncoding];
? ? NSDictionary*dict = [ViewControllerjsonStrtodictWithStr:nsString];
? ? NSLog(@"dict==aihelp==%@",dict);
? ? inteventType = [[dictobjectForKey:@"eventType"]intValue];
? ? if(eventType ==0) {
? ? ? ? BOOLisSuccess = [[dictobjectForKey:@"isSuccess"]boolValue];
? ? ? ? if(isSuccess) {
? ? ? ? ? ? isInit=YES;
? ? ? ? }else
? ? ? ? {
? ? ? ? ? ? isInit=NO;
? ? ? ? }
? ? }elseif(eventType ==5)
? ? {
? ? ? ? NSLog(@"messageCount==未读消息数量=%@",[dict objectForKey:@"msgCount"]);
? ? }
}