BlipSDK 0.0.24

BlipSDK 0.0.24

许可协议 Apache 2
发布最新发布2017 年 5 月

Blip 团队 维护。



BlipSDK 0.0.24

  • 夺取

适用于 iOS 的 Blip SDK

SDK 旨在轻松将 BLiP 聊天功能添加到您的 iOS 应用中。更多信息请参阅 BLiP 门户BLiP 文档

安装

先决条件

要使用 Blip SDK for iOS,您的目标必须为 iOS 10 或更高版本。

通过 CocoaPods 将 Blip SDK for iOS 导入到您的项目中

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

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

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

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

    注意:请勿使用 *.xcodeproj。如果您打开项目文件而不是工作区,将会收到错误。

如何使用

快速入门

设置您的 SDK

在您的项目中添加了 SDK 引用后,您需要在 BLiP 门户 上获取您的 API 密钥。转到左侧菜单并访问 Publications > Blip Chat

要使用位置信息卡,在 info.plist 文件中设置位置服务的使用描述密钥。使用密钥 Privacy - Location When In Use Usage Description 并设置一条消息,请求用户允许使用位置信息。

打开新的 Blip 聊天

  1. 导入 BlipSKD

    Swift

    import BlipSDK

    Objective-C

    #import "BlipSDK/BlipSDK-Swift.h"
  2. 打开一个新的帖子非常简单。使用 BlipClient 辅助类并调用 openBlipThread 方法。

    Swift

    BlipClient.openBlipThread(myView: self, apiKey: "your-api-key", options: nil)

    Objective-C

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

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

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

    Swift

    import UIKit
    import WebKit
    import BlipSDK
    
    class ViewController: UIViewController {
    
    	override func viewDidLoad() {
    		super.viewDidLoad()
    	}
    
    	override func viewDidAppear(_ animated: Bool) {
    		do {
            	try BlipClient.openBlipThread(myView: self, apiKey: "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 "BlipSDK/BlipSDK-Swift.h"
    
    @interface ViewController ()
    @end
    
    @implementation ViewController
    
    - (void)viewDidAppear:(BOOL)animated {
    	[super viewDidAppear: animated];
    	[BlipClient openBlipThreadWithMyView:self apiKey:(NSString*) @"your-api-key" options:nil error: nil];
    }
    
    - (void)didReceiveMemoryWarning {
    	[super didReceiveMemoryWarning];
    	// Dispose of any resources that can be recreated.
    }
    @end

高级功能

定义身份验证类型

BLiP iOS SDK支持三种不同的用户身份验证类型。可以定义BLiP SDK将使用哪种身份验证方法来识别您的客户端。

  • 访客 - 用户将获得一个访客账户,以便与聊天机器人交互。在此模式下,用户没有消息历史。
  • 登录 - 用户将获得一个包含其“名称”和“电子邮件”(由用户提供)的账户,以便与聊天机器人交互。在此模式下,用户没有消息历史。
  • 开发者 - 用户将获得一个由开发者指定的账户,以便与聊天机器人交互。必须通过将BlipOptions实例作为参数传递给BlipClient.openThread方法来提供用户数据。您可以设置4个属性:userIdentifieruserPassworduserNameuserEmailUserIdentifieruserPassword必需的。在此模式下,用户有消息历史。

要定义使用的用户身份验证类型,请在BlipOptions的authType属性中使用AuthTypeProvider.AuthType枚举。当使用Swift时,authType的可能值有:.Guest.Login.Dev。当使用Objective-C时,可能的值有:AuthTypeGuestAuthTypeLoginAuthTypeDev

注意:如果您没有定义'authType',默认将使用访客类型。

Swift

 let options = BlipOptions(authType: .Dev,
                                  userIdentifier: "user-identifier",
                                  userPassword: "user-password",
                                  userName: "user-name",
                                  userEmail: "user-email")

Objective-C

BlipOptions *options = [[BlipOptions alloc] init];
options.authType = AuthTypeDev;
options.userIdentifier = @"user-identifier";
options.userPassword = @"user-password";
options.userName = @"user-name";
options.userEmail = @"user-email";

设置聊天窗口的标题

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

Swift

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

Objective-C

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

示例设置窗口标题和使用开发者身份验证类型

Swift

import UIKit
import WebKit
import BlipSDK

class ViewController: UIViewController {
	
	override func viewDidLoad() {
		super.viewDidLoad()
	}
	
	override func viewDidAppear(_ animated: Bool) {
		let options = BlipOptions(authType: .Dev,
                                  userIdentifier: "user-identifier",
                                  userPassword: "user-password",
                                  userName: "user-name",
                                  userEmail: "user-email")
		options.windowTitle = "window-title"

		do {
            try BlipClient.openBlipThread(myView: self, apiKey: "your-api-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 "BlipSDK/BlipSDK-Swift.h"


@interface ViewController ()
@end

@implementation ViewController

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

	BlipOptions *options = [[BlipOptions alloc] init];
    options.authType = AuthTypeDev;
    options.userIdentifier = @"user-identifier";
    options.userPassword = @"user-password";
    options.userName = @"user-name";
    options.userEmail = @"user-email";
    options.windowTitle = @"window-title";
    
    [BlipClient openBlipThreadWithMyView:self apiKey:(NSString*) @"your-api-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. 将您的构建设置变量Runpath Search Paths设置为@executable_path/Frameworks

your_target -> Build Settings -> Linking -> Runpath Search Paths

  1. 将构建设置变量Always Embed Swift Standard Libraries切换到Yes

your_target -> Build Settings -> Build Options -> Always Embed Swift Standard Libraries

有关更详细的解释,请参阅stackoverflow上的这个主题:http://stackoverflow.com/questions/26104975/dyld-library-not-loaded-rpath-libswiftcore-dylib-image-not-found

B -> 应用传输安全已阻止HTTP (http://) 资源

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

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

  2. 将密钥NSAppTransportSecurity添加到您的app info.plist中。

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

许可

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.