GetivySDK 2.0.2

GetivySDK 2.0.2

Marius KurgonasSimon Wimmer 维护。



GetivySDK 2.0.2

  • Simon Wimmer

#GetivySDK

内容

最新版本需求

  • Xcode 13.4+
  • Swift 5.6+

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。

在项目的 Podfile 中指定 GetivySDK

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!

pod 'GetivySDK'

然后运行以下命令

$ pod install

Swift 包管理器

Swift 包管理器 是用于管理 Swift 代码分布的工具。

设置完您的 Package.swift 清单文件后,您可以通过将其添加到 Package.swift 的依赖项值中来将 GetivySDK 作为依赖项添加。

dependencies: [ .package(url: "https://github.com/getivy/ios-sdk-prod.git", from: "1.0.3") ]

Carthage

Carthage 是用于 Cocoa 的简单、去中心化的依赖管理器。

在项目的 Cartfile 中指定 GetivySDK

github "getivy/ios-sdk-prod" ~> 1.0.3

作为嵌入式框架手动安装

  • 在您的项目根 git 文件夹中运行以下命令,通过 git submodule 克隆 GetivySDK。
$ git submodule add https://github.com/getivy/ios-sdk-prod.git
  • GetivySDK.xcframework 拖至您项目中,并在包含它到您的应用程序目标中选择。

  • 选择您的目标的 "General" 选项卡,确保框架出现在 "Embedded Binaries" 部分,并且已选择 "Embedd and Sign"。

  • 现在您可以构建和运行您的应用程序了。

开始操作流程

如何启动流程

以下示例说明如何初始化SDK并获取一个UI处理程序,您可以使用它来启动SDK的流程。

import UIKit
import GetivySDK

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
                
        // Create an SDK configuration
        let config = GetivyConfiguration(
            dataSessionId: <data session id string>,
            onSuccess: { result in }, 
            onError: { error in }
        )
        
        // Get reference to the SDK
        let sdk = GetivySDK.shared
        
        // Get UI handler
        sdk.initializeHandler(configuration: config) { handler, error in
            handler?.openUI(viewController: self) // Set a view controller for SDK to present its UI over and start the flow
        }
    }
}

更多控制

为了控制SDK界面如何展示,您可以使用替代调用来展示UI处理程序。

import UIKit
import GetivySDK

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
                
        // Create an SDK configuration
        let config = GetivyConfiguration(
            dataSessionId: <data session id string>,
            onSuccess: { result in }, 
            onError: { error in }
        )
        
        // Get reference to the SDK
        let sdk = GetivySDK.shared
        
        // Get UI handler
        sdk.initializeHandler(configuration: config) { handler, error in
            handler?.openUI(presentationCosure: { sdkViewController in 
                // presentation closure will get called with a reference to the main SDK view controller so the app can control the presentation
            }, dismissalClosure: { sdkViewController in
                // dismiss callback insicates that sdk should be removed from the apps UI in case it finished or there was a non recoverable error
            })
        }
    }
}

在沙盒中测试

在进行发布前,请指定创建配置时额外的环境参数。

    // Create an SDK configuration
    let config = GetivyConfiguration(
        dataSessionId: <data session id string>,
        environment: "production",
        onSuccess: { result in }, 
        onError: { error in }
    )

可能的环境值:productionsandbox

OnSuccess

在创建SDK配置时,存在一个名为onSuccess的回调,在用户成功完成流程时调用。在这种情况下,事件详情以对象的形式返回,包含SDK用于启动流程的原始数据会话ID以及完成流程的引用ID。

OnError

当创建SDK配置时,如果在流程中出现错误,将会调用onError回调。将提供详细错误的错误对象以便相应操作。