BlipChat 2.2.5-beta2

BlipChat 2.2.5-beta2

许可证 Apache-2.0
发布最后发布2021年8月

Blip TeamLuiz Guilhermeblip 维护。



BlipChat 2.2.5-beta2

  • 拿取

BLiP Chat for iOS

SDK,可轻松将 BLiP Chat 组件添加到您的 iOS 应用中。有关更多信息,请参阅 BLiP 门户BLiP 文档。查看支持的版本 此处

安装

先决条件

要使用 BLiP Chat for iOS,您必须针对 iOS 10 或更高版本。

通过 CocoaPods 将 BLiP Chat for iOS 添加到项目中

  1. 如果您尚未安装 CocoaPods,请运行以下命令安装它:

     $ [sudo] gem install cocoapods
     $ pod setup
    
  2. 在项目目录中创建一个名为 Podfile 的纯文本文件(不带任何文件扩展名)。将以下行添加到您的文件中,并用您的实际目标名称替换 YourTarget

     target 'YourTarget' do
       use_frameworks!
       pod "BlipChat"
     end
    
  3. 运行以下命令。

     $ pod install
    
  4. 使用 Xcode 打开 *.xcworkspace 并开始使用 SDK。

    注意:不要使用 *.xcodeproj。如果您打开项目文件而不是工作空间,您将接收到错误。

如何使用

快速开始

配置SDK

在您的项目包含SDK引用后,您需要从BLiP网关获取您的App Key。转到左侧菜单并访问发布 > Blip Chat。在设置选项卡中,您将能够获取所需的App Key。您还需要在域名部分注册您的iOS App Id,以便在您的应用中启用聊天机器人。

要使用位置卡片,请在info.plist文件中设置定位服务的使用描述密钥。使用密钥隐私 - 使用时位置使用描述,设置一条消息请求用户允许使用其位置。

打开新的Blip对话

  1. 导入BLiP SDK

    Swift

    import BlipChat

    Objective-C

    #import "BlipChat/BlipChat.h"
  2. 要打开一个新的话题非常简单:使用< strong>BlipClient辅助类并调用openBlipThread方法。

    Swift

    BlipClient.openBlipThread(myView: self, appKey: "your-app-key", options: nil)

    Objective-C

    [BlipClient openBlipThreadWithMyView:self appKey:(NSString*) @"your-api-key" options:options error: nil];

    注意:在Objective-C中,方法名是openBlipThreadWithMyView

    例如,假设您想在加载ViewController时建立客户与聊天机器人之间的新对话。

    Swift

    import UIKit
    import WebKit
    import BlipChat
    
    class ViewController: UIViewController {
    
    	override func viewDidLoad() {
    		super.viewDidLoad()
    	}
    
    	override func viewDidAppear(_ animated: Bool) {
    		do {
            	try BlipClient.openBlipThread(myView: self, appKey: "your-api-key", options: nil)
    		} catch {
    			print (error.localizedDescription)
    		}
    	}
    
    	override func didReceiveMemoryWarning() {
    		super.didReceiveMemoryWarning()
    		// Dispose of any resources that can be recreated.
    	}
    }

    Objective-C

    #import "ViewController.h"
    #import "BlipChat/BlipChat.h"
    
    @interface ViewController ()
    @end
    
    @implementation ViewController
    
    - (void)viewDidAppear:(BOOL)animated {
    	[super viewDidAppear: animated];
    	[BlipClient openBlipThreadWithMyView:self appKey:@"your-app-key" options:nil error: nil];
    }
    
    - (void)didReceiveMemoryWarning {
    	[super didReceiveMemoryWarning];
    	// Dispose of any resources that can be recreated.
    }
    @end

高级功能

定义认证类型

BLiP Chat iOS SDK支持两种不同的用户认证类型。您可以定义用于识别客户端的认证方法。

  • 访客 - 用户将接收到一个访客账户以与聊天机器人互动。在这种模式下,用户将没有消息记录。
  • 开发人员将向用户发放一个账户,用户可通过该账户与聊天机器人交互。用户数据必须通过传递BlipOptions实例作为参数调用BlipClient.openThread方法来提供。您必须设置两个属性:userIdentityuserPassword。在此模式下,用户将有消息历史。

为了定义用户认证类型,请使用AuthTypeProvider.AuthType枚举的BlipOptions的authType属性。当使用Swift时,authType的可能值是:.Guest.Dev。当使用Objective-C时,可能值是:AuthTypeGuestAuthTypeDev

注意:如果未定义authType,则将使用访客类型。

Swift

let authConfig = AuthConfig(authType: .Dev, userIdentity: "user-identifier", userPassword: "user-password")
options = BlipOptions(authType: authConfig, account: nil)

Objective-C

AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"user-identifier" userPassword:@"user-password"];
options = [[BlipOptions alloc] initWithAuthType:authConfig account: nil];

指定用户数据

BLiP Chat允许指定用户的诸如fullnameemail等数据。有关可能的属性和支持的更多详细信息,请参阅Lime文档

要设置用户数据,只需创建一个Account对象并将其作为参数传递给BlipOptions

Swift

let authConfig = AuthConfig(authType: .Dev, userIdentity: "user-identifier", userPassword: "user-password")
let account = Account(fullname: "user-name", email: "user-email")
options = BlipOptions(authType: authConfig, account: account)

Objective-C

AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"user-identifier" userPassword:@"user-password"];
Account *account = [[Account alloc] initWithFullname:@"user-name" email:@"user-email"];
options = [[BlipOptions alloc] initWithAuthType:authConfig account: account];

为聊天窗口设置标题

在iOS中,您可以设置聊天视图的标题。此标题将显示在ModalView的顶部。

Swift

let options = BlipOptions()
options.windowTitle = "Window Title"

Objective-C

BlipOptions *options = [[BlipOptions alloc] init];
options.windowTitle = @"Window Title";

为聊天设置自定义URL

要在BLiP Chat的iOS SDK中使用机构,您必须将选项分配给您组织的BLiP Chat URL。

Swift

let authConfig = AuthConfig()

// Use your organization BLiP Chat URL
let options = BlipOptions(authType: authConfig, account: nil, connectionDataConfig: nil, customCommonUrl: "https://take.chat.blip.ai/", customWidgetUrl: nil, windowTitle: nil)

Objective-C

AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"user-identifier" userPassword:@"user-password"];
options = [[BlipOptions alloc] initWithAuthType:authConfig account: nil connectionDataConfig: nil customWidgetUrl: nil windowTitle: nil];

// Use your organization BLiP Chat URL
options.customCommonUrl = @"https://take.chat.blip.ai/";

使用Dev认证类型设置窗口标题

Swift

import UIKit
import WebKit
import BlipChat

class ViewController: UIViewController {
	
	override func viewDidLoad() {
		super.viewDidLoad()
	}
	
	override func viewDidAppear(_ animated: Bool) {
		let authConfig = AuthConfig(authType: .Dev, userIdentity: "user-identifier", userPassword: "user-password")
		let account = Account(fullname: "user-name", email: "user-email")
		let options = BlipOptions(authType: authConfig, account: account)
		options.windowTitle = "window-title"
		
		do {
        		try BlipClient.openBlipThread(myView: self, appKey: "your-app-key", options: options)
        	} catch {
            		print (error.localizedDescription)
        	}
	}
	
	override func didReceiveMemoryWarning() {
		super.didReceiveMemoryWarning()
		// Dispose of any resources that can be recreated.
	}
}

Objective-C

#import "ViewController.h"
#import "BlipChat/BlipChat.h"


@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidAppear:(BOOL)animated {
	[super viewDidAppear: animated];

	AuthConfig *authConfig = [[AuthConfig alloc] initWithAuthType:AuthTypeDev userIdentity:@"user-identifier" userPassword:@"user-password"];
	Account *account = [[Account alloc] initWithFullname:@"user-name" 	email:@"user-email"];
	BlipOptions *options = [[BlipOptions alloc] initWithAuthType:authConfig account:account];
	options.windowTitle = @"window-title";
    
    [BlipClient openBlipThreadWithMyView:self appKey: @"your-app-key" options:options error: nil];
}

- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning];
	// Dispose of any resources that can be recreated.
}

@end

故障排除

A -> dyld: 库未找到: @rpath/libswiftCore.dylib / 图片未找到

Objective-C 项目可能会出现库未加载的错误。

如果出现这种情况,请按照以下步骤操作

  1. 将您的构建设置变量 运行路径搜索路径 设置为 @executable_path/Frameworks

your_target -> 构建设置 -> 链接 -> 运行路径搜索路径

  1. 将构建设置变量 始终嵌入 Swift 标准库 切换到

your_target -> 构建设置 -> 构建选项 -> 始终嵌入 Swift 标准库

更详细的说明,请参阅 Stack Overflow 上的这个帖子 http://stackoverflow.com/questions/26104975/dyld-library-not-loaded-rpath-libswiftcore-dylib-image-not-found

B -> App Transport Security 已阻止 HTTP (http://) 资源

如果出现这种情况,您有两个选择

  1. 在您的聊天机器人中只使用 HTTPS 资源。

  2. 将密钥 NSAppTransportSecurity 添加到您的应用 info.plist。

  • 打开您的项目 info.plist 文件。
  • 添加一个名为 NSAppTransportSecurity 的键,作为一个字典。
  • 添加一个名为 NSAllowsArbitraryLoads 的子键,作为布尔值,将其值设置为 YES,如图所示。

支持


iOS 10以上。

许可

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.