yoti-sdk 4.0.1

yoti-sdk 4.0.1

John MillsYoti iOS Teamyoti-sdk’ --description=marios.kotsiandris’ 维护。



yoti-sdk 4.0.1

Carthage compatible Cocoapods compatible Platform

ios-sdk-button

移动 SDK 的目的是为了使第三方应用程序能够在利用 Yoti 移动应用的同时,从 Yoti 用户请求属性。这是一个由非常轻量级的 SDK 促成的第三方应用程序和 Yoti 应用之间的交互。这个仓库包含工具和一步一步的说明,以便您的用户能够以安全可信的方式与应用程序共享他们的身份信息。

要求

  • 您需要在手机上安装 Yoti 应用
  • 您需要确保部署目标的最小版本为 9.0 或更高。
  • 您需要 Xcode 10.2 或更高版本

安装 SDK

安装移动 SDK 有三个部分需要完成

  1. 首先,请按照我们的 Yoti 仪表盘流程操作。您需要在这里创建一个组织。组织创建后,您需要创建一个 Yoti 应用。如果您正在测试或使用 Yoti 进行个人用途,请直接在这里创建应用。

    创建应用过程将为您生成密钥。请妥善保管您的 SDK ID 和场景 ID 以便进行移动集成。

    有关更多信息,请根据我们的开发者页面说明进行操作,说明位于这里

  2. 安装网络 SDK。请浏览我们的 GitHub 页面并在您的网络后端初始化网络 SDK。

    有关更多信息,请根据我们的开发者页面说明进行操作,说明位于这里

  3. 安装移动 SDK。可以通过以下三种方法中的任何一种完成

    • Carthage - 首选偏好设置
    • Cocoapods
    • 拖放

Carthage(推荐)

Carthage 是一个去中心化的依赖管理器,它构建依赖并为你提供二进制框架。

你可以使用以下命令通过 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 将 Yoti 集成到你的 Xcode 项目中,请在你的 Cartfile 中指定它

github "getyoti/ios-sdk-button" ~> 2.4.0

这将允许你在终端中输入 carthage update ios-sdk-button 以获取和构建框架的最新版本。第一次集成 iOS SDK 时,动态框架将在 Carthage/Build/iOS/ 下生成。

将构建的 YotiButtonSDK.framework 拖入你的 Xcode 项目而不复制它。不要提交 Carthage 文件夹,但提交 Carthage.resolved 文件。

每次你想获取依赖项时,都可以输入 carthage bootstrap

CocoaPods

CocoaPods 是用于 Swift 和 Objective-C Cocoa 项目的依赖管理器。

使用默认的 Ruby 安装可能需要在安装 gems 时使用 sudo。进一步的安装说明请在 指南 中查看。

$ sudo gem install cocoapods

要使用 Cocoapods 将 Yoti 集成到你的 Xcode 项目中,请在你的 Podfile 中指定它

pod 'yoti-sdk', '~> 2.4.0'

提示:CocoaPods 提供了一个 pod init 命令,可以创建具有智能默认设置的 Podfile。你应该使用它。

现在你可以安装项目中的依赖了

$ pod install

确保在构建项目时始终打开 Xcode 工作区而不是项目文件。

拖放(不推荐)

你也可以通过添加子模块的方式添加 Yoti SDK,并将 Yoti 的项目文件拖入你的项目中。

配置

在开始配置之前,您需要在构建阶段添加 Yoti SDK:前往您的项目,然后转到 构建阶段 选项卡,点击最左上角的 +,选择 新建复制文件阶段 并将 目标位置 更改为 框架

在新的阶段上点击 + 并选择 YotiButtonSDK.framework,然后点击 添加

导航到您想集成 Yoti 按钮的位置,添加一个按钮并将类更改为 YotiButton。

: YotiButton

模块: YotiButtonSDK

添加一个 用户定义的运行时属性:类型为 String 的 useCaseID,其值可以用来识别按钮。

Yoti 按钮

SDK 提供了一个自定义按钮,您可以在布局中使用它,不要忘记设置 useCaseID,它是与 场景 的链接。请参阅下面的定义。或者您也可以像这样在代码中定义按钮

Swift

import YotiButtonSDK

let button = YotiButton(frame: CGRect(x: 0, y: 0, width: 230, height: 48))
button.useCaseID = "YOUR_USE_CASE_ID"

如果您使用了 Cocoapods,请使用以下内容

import yoti_sdk

let button = YotiButton(frame: CGRect(x: 0, y: 0, width: 230, height: 48))
button.useCaseID = "YOUR_USE_CASE_ID"

Objective-C

#import <YotiButtonSDK/YotiButtonSDK.h>                                                                                                           
YotiButton* button = [[YotiButton alloc] initWithFrame:CGRectMake(0, 0, 230, 48)]
button.useCaseID = "YOUR_USE_CASE_ID"

前端集成现在已完成。

创建场景

您现在需要从应用仪表板上准备好 SDK ID、场景 ID 和回调 URL。

对于您想要处理的每个场景,您需要将它们添加到 YotiSDK 中,如下所示

Swift:请将场景方法添加到您的 AppDelegate.swift 中

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool

如下。

import YotiButtonSDK

    do {
        guard let url = URL(string: "YOUR_CALLBACK_URL") else {
            return false
        }
        //Here we need to add as many scenarios as we want. each scenario is linked to a button in the Main.storyboard.
        let firstScenario = try ScenarioBuilder().setUseCaseID("YOUR_FIRST_USE_CASE_ID")
        .setClientSDKID("YOUR_FIRST_CLIENT_SDK_ID")
        .setScenarioID("YOUR_FIRST_SCENARIO_ID_1")
        .setCallbackBackendURL(url)
        .create()
        YotiSDK.add(scenario: firstScenario)
                 
        let secondScenario = try ScenarioBuilder().setUseCaseID("YOUR_SECOND_USE_CASE_ID")
        .setClientSDKID("YOUR_SECOND_CLIENT_SDK_ID")
        .setScenarioID("YOUR_SECOND_SCENARIO_ID_2")
        .setCallbackBackendURL(url)
        .create()
        YotiSDK.add(scenario: secondScenario)
    } catch {
        // handle error code here
    }
}

Objective-C:请将场景方法添加到您的 appDelegate.m 中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

如下

#import <YotiButtonSDK/YotiButtonSDK.h>

    NSError* error = nil;
    YTBScenarioBuilder *firstScenarioBuilder = [[YTBScenarioBuilder alloc] init];
    firstScenarioBuilder.useCaseID = @"YOUR_FIRST_USE_CASE_ID";
    firstScenarioBuilder.clientSDKID = @"YOUR_FIRST_CLIENT_SDK_ID";
    firstScenarioBuilder.scenarioID = @"YOUR_FIRST_SCENARIO_ID";
    firstScenarioBuilder.callbackBackendURL = [NSURL URLWithString:@"YOUR_CALLBACK_URL"];
    YTBScenario *firstScenario = [firstScenarioBuilder create:&error];
    [YotiSDK addScenario: firstScenario];

    error = nil;
    YTBScenarioBuilder *secondScenarioBuilder = [[YTBScenarioBuilder alloc] init];
    secondScenarioBuilder.useCaseID = @"YOUR_SECOND_USE_CASE_ID";
    secondScenarioBuilder.clientSDKID = @"YOUR_SECOND_CLIENT_SDK_ID";
    secondScenarioBuilder.scenarioID = @"YOUR_SECOND_SCENARIO_ID";
    secondScenarioBuilder.callbackBackendURL = [NSURL URLWithString:@"YOUR_CALLBACK_URL"];
    YTBScenario *secondScenario = [secondScenarioBuilder create:&error];
    [YotiSDK addScenario: secondScenario];

    return YES;

然后在您的 viewController 类中,在按钮的 IBAction 函数中调用该函数

public static func startScenario(for useCaseID: String, with delegate: YotiSDKDelegate) throws 

接下来,转到包含 YotiButton 输出的视图控制器。在其 IBAction 中调用 Swift 中的 SDK 方法签名或 Objective-C 中的签名。

Swift

@IBAction func yotiButtonDidTouchUpInside(_ sender: YotiButton) {
    guard let useCaseID = sender.useCaseID else {
        return
    }
    do {
        UIApplication.shared.isNetworkActivityIndicatorVisible = true
        try YotiSDK.startScenario(for: useCaseID, with: self)
    } catch {
        // Handle error here
    }
}

Objective-C

- (IBAction)buttonDidTouchUpInside:(YotiButton*)sender {
    NSString* useCaseID = sender.useCaseID;
    NSError* error = nil;

    if (![useCaseID isEqual:@""]) {
        [YotiSDK startScenarioForUseCaseID:useCaseID withDelegate:self error:&error];

        if (error != nil) {
            NSLog(@"error : %@", error.description);
        }
    }
}

在 Swift 中,您的 ViewController 类应遵守 YotiSDKDelegate 和 BackendDelegate,以便获取回调。

extension ViewController: YotiSDKDelegate {
    func yotiSDKDidFail(for useCaseID: String, with error: Error) {
    	// handle here the error related to the failing of retrieving a usecaseID and a token
    }

    func yotiSDKDidSucceed(for useCaseID: String, baseURL: URL?, token: String?, url: URL?) {
        // Handle here the success of the opening of Yoti app for example by requesting a profile from the backend like below
        // Get the specific scenario by calling  
        let scenario = YotiSDK.scenario(for: useCaseID)
        // request the backend to get the profile linked to a specific scenario by passing the token returned and self as delegate for a call back
        YotiSDK.callbackBackend(scenario: scenario!, token: token!, with: self)
    }

    func yotiSDKDidOpenYotiApp() {
        // Handle specific behaviour if needed when the Yoti App didOpen
    }
}

In Objective-C,你的 viewController 应该遵守YTBSDKDelegate 和 YTBBackendDelegate,如下所示

@interface ViewController () <YTBSDKDelegate, YTBBackendDelegate>

在Swift中,BackendDelegate是它的名称,而YTBBackendDelegate命名空间是针对Objective-C的。请注意,遵循YTBBackendDelegate是可选的,因为这可能取决于您是否依赖后端来实现您的场景。我们的当前实现依赖于后端来执行我们的场景。

我们按照这种方式实现了ViewController所遵守的协议的代理函数

- (void)yotiSDKDidFailFor:(NSString * _Nonnull)useCaseID with:(NSError * _Nonnull)error {
    // handle failure here
}

- (void)yotiSDKDidSucceedFor:(NSString * _Nonnull)useCaseID baseURL:(NSURL * _Nullable)baseURL token:(NSString * _Nullable)token url:(NSURL * _Nullable)url {
	YTBScenario *scenario = [YotiSDK scenarioforUseCaseID:useCaseID];
	[YotiSDK callbackBackendScenario:scenario token:token withDelegate:self];
}

- (void)yotiSDKDidOpenYotiApp {
	// behaviour when SDK opens yoti app (if needed)
}

当回调从后端返回时,我们会获取与配置文件或错误关联的数据

Swift

func backendDidFinish(with data: Data?, error: Error?)

Objective-C

- (void)backendDidFinishWith:(NSData * _Nullable)data error:(NSError * _Nullable)error

通知

如果您在我们执行网络请求之前需要更改您的界面,您可以从YotiSDK类订阅willMakeNetworkRequestdidFinishNetworkRequest通知

Swift

NotificationCenter.default.addObserver(forName: YotiSDK.willMakeNetworkRequest, object: nil, queue: nil) { (notification) in
    // Disable interface
}
NotificationCenter.default.addObserver(forName: YotiSDK.didFinishNetworkRequest, object: nil, queue: nil) { (notification) in
    // Re-enable interface
}

Objective-C

[NSNotificationCenter.defaultCenter addObserverForName:YotiSDK.willMakeNetworkRequest object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
    // Disable interface
}];
[NSNotificationCenter.defaultCenter addObserverForName:YotiSDK.didFinishNetworkRequest object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
    // Re-enable interface
}];

应用间通信

Yoti SDK会切换到Yoti应用并返回到您的应用以完成共享过程,您的应用.plist也需要处理这一点。

添加您的URL Scheme

<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>YOUR_URL_SCHEME</string>
  </array>
  </dict>
</array>

将Yoti添加为查询方案

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>yoti</string>
</array>

将应用程序生命周期通知给Yoti SDK

Swift

import YotiButtonSDK

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ app: UIApplication,
                     open url: URL,
                     options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return YotiSDK.application(app, open:url, options:options)
    }
}

Objective-C

#import <YotiButtonSDK/YotiButtonSDK.h>

@implementation AppDelegate
  - (BOOL)application:(UIApplication *)app
              openURL:(NSURL *)url
              options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
      return [YotiSDK application:app open:url options:options];
  }
@end

处理用户

Web SDK将处理用户存储。当你检索用户资料时,你将获得Yoti为你应用程序独家生成的用户ID。这意味着如果同一个人在其他应用程序中登录,Yoti将为她/他分配不同的ID。你可以使用此ID验证该检索到的资料是否代表你的应用程序中的新用户或现有用户。请参阅相关GitHub页面以获取更多信息。

支持

如果您有任何疑问或需要支持,请通过电子邮件咨询[邮箱 保护]。为了尽快让您开始工作,请提供以下信息:

  • 手机上的软件版本
  • Web SDK的语言
  • 错误截图

一旦我们回答了您的问题,我们可能会再次联系您,讨论Yoti的产品和服务。如果您希望我们不这样做,请在发出电子邮件时告诉我们。