qKit 0.1

qKit 0.1

daQiuQiu 维护。



 
依赖项
SnapKit~> 4.0.0
Alamofire>= 0
DLRadioButton>= 0
SDWebImage>= 0
 

qKit 0.1

  • 作者:
  • daQiuQiu

iOS SDK

ATP Kit 是 Atlas Protocol 的一部分组件,与区块链交互以获取 TIE(目标交互元素)。

此库适用于 iOS 设备。

安装指南(待办)

!Cocoapod 尚未配置。

调用 SDK (Swift)

重要:对于 Objective-C 开发者!如果您想在 Objective-C 项目中使用 Swift SDK,请至少在项目编译源中包括一个 SWIFT 文件,以便自动链接 Swift 标准库。

导入 SDK

import ATPKit
import Renderer

定义端点

public class Constants {
  // MARK: List of Constants
  public static let baseEP = "http://test-ces.atpsrv.net/v1"
  public static let campaignID = "cbehlkl7if2mfav8aof1g"
}

重写投票渲染器

public class VotingViewController: VotingRenderer {
  override open func register(nasAddress: String, completion: @escaping (TIE?) -> Void) throws {
    try KitFactory.sharedInstance.getKitBuilder().register(nasAddress: nasAddress, completion: completion)
  }

  override open func parseTIE(tie: TIE) throws -> VoteData {
    return try KitFactory.sharedInstance.getKitBuilder().parseTIE(tie: tie) as! VoteData
  }

  override open func vote(_ vote: Vote, completion: @escaping (String?) -> Void) throws {
    try KitFactory.sharedInstance.getKitBuilder().delegateInteract(atpEvent: vote, completion: completion)
  }

  override open func getCampaignID() -> String {
    return Constants.campaignID
  }

  override open func setupKit() {
    KitFactory.setup(type: TIEType.voting.rawValue)
    let kitBuilder: KitBuilder = KitFactory.sharedInstance.getKitBuilder()
    kitBuilder.initSDK(atpConfig: ATPConfig(baseEP: Constants.baseEP, campaignID: Constants.campaignID, lang: "en", accid: "2312313", msg: "Thank you for your participation"))
  }
}

由于故事板是手动配置的,请继续配置 Main.storyboard

<viewController storyboardIdentifier="VotingViewController" id="4JQ-qw-sF2" customClass="VotingViewController" customModule="Starter" sceneMemberID="viewController">
  ...
</viewController>

如果您想通过 AppDelegate 启动 ATPKit(SDK),可以这样做:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    setupKit()
    return true
  }

  // MARK: SDK Setup Sample
  private func setupKit() {
    KitFactory.setup(type: TIEType.voting.rawValue)
    let kitBuilder: KitBuilder = KitFactory.sharedInstance.getKitBuilder()
    kitBuilder.initSDK(atpConfig: ATPConfig(baseEP: Constants.baseEP, campaignID: Constants.campaignID, lang: "en", accid: "2312313", msg: "Thank you for your participation"))
  }

  // MARK: Dispatch Sample
  // MARK: DO NOT Know how to bind to story board
  private func getViewController(kitBuilder: KitBuilder) -> ATPRenderer {
    guard let mainViewController = kitBuilder.dispatch(adForm: nil) else {
      return VotingViewController()
    }
    return mainViewController
  }
}

可以从 ATPKit 方法 dispatch 获取视图控制器。(不再使用)

针对 SDK 开发者

本地项目构建

第一次构建时,您必须手动构建 ATPKit.framework 和 Render.framework。之后,您只需运行 Example 演示应用程序,它们将自动构建。

$ cd ../Render
$ pod install
$ cd ../ATPKit
$ pod install
$ cd ../Example
$ pod install
ld: file too small (length=0)

如果您遇到了上面的错误,请再次运行 pod install 这些项目或者尝试清理构建文件夹。

词汇表

.
├── ATPKit
│   ├── ATPKit
│   │   ├── API
│   │   │   ├── HTTPClient.swift
│   │   │   └── LibraryAPI.swift
│   │   ├── ATPKit.h
│   │   ├── Config
│   │   │   └── ATPConfig.swift
│   │   ├── Helper
│   │   │   ├── Connectivity.swift
│   │   │   └── ATPKitError.swift
│   │   ├── Info.plist
│   │   ├── Services
│   │   │   ├── ATPManager.swift
│   │   │   ├── KitBuilder.swift
│   │   │   ├── KitFactory.swift
│   │   │   └── VotingManager.swift
│   │   └── TIERenderer.swift
│   ├── ATPKitTests
│   │   ├── ATPKitTests.swift
│   │   └── Info.plist
├── Example
│   ├── ATPKit.framework
│   │   ├── ATPKit
│   │   ├── Headers
│   │   │   ├── ATPKit-Swift.h
│   │   │   └── ATPKit.h
│   │   ├── Info.plist
│   │   └── Modules
│   │       ├── ATPKit.swiftmodule
│   │       │   ├── arm64.swiftdoc
│   │       │   └── arm64.swiftmodule
│   │       └── module.modulemap
│   ├── README.md
│   ├── Renderer
│   │   └── Renderer.xcodeproj
│   ├── Starter
│   │   ├── AppDelegate.swift
│   │   ├── Base.lproj
│   │   │   ├── LaunchScreen.xib
│   │   │   └── Main.storyboard
│   │   ├── Constants.swift
│   │   ├── FinishViewController.swift
│   │   ├── Images.xcassets
│   │   │   ├── AppIcon.appiconset
│   │   │   │   ├── Contents.json
│   │   │   │   ├── atp-logo-3.png
│   │   │   │   ├── atp-logo.png
│   │   │   │   ├── atp1024.png
│   │   │   │   ├── atp180.png
│   │   │   │   ├── atp58.png
│   │   │   │   ├── atp80.png
│   │   │   │   └── atp87.png
│   │   │   └── Contents.json
│   │   ├── Info.plist
│   │   ├── VotingViewController.swift
│   │   └── projects.json
│   └── StarterTests
│       ├── Info.plist
│       └── StarterTests.swift
└── Renderer
    ├── DLRadioButton
    ├── README.md
    ├── Renderer
    │   ├── Controllers
    │   │   ├── ATPRenderer.swift
    │   │   └── VotingRenderer.swift
    │   ├── Helper
    │   │   ├── Constants.swift
    │   │   └── Errors.swift
    │   ├── Info.plist
    │   ├── Models
    │   │   ├── ADForm.swift
    │   │   ├── ATPEvent.swift
    │   │   ├── Account.swift
    │   │   ├── TIE.swift
    │   │   ├── Vote.swift
    │   │   └── VoteData.swift
    │   ├── Renderer.h
    │   └── Views
    │       └── 
    ├── Renderer.xcodeproj
    ├── Renderer.xcworkspace
    ├── RendererTests
        ├── Info.plist
        └── RendererTests.swift
    

CI/CD

bitbucket 管道脚本如下:

pipelines:
  custom:
    devios:
      - step:
          name: Build iOS Pods
          image: davidthornton/node6-cocoapods
          script:
            - chown -R node ios
            - export LANG=en_US.UTF-8
            - su node
            - cd ios/Renderer
            - pod trunk register [email protected] 'Bill Lv' --description='Atlas Protocol'
            - pod trunk push Renderer.podspec
            - cd ../..
            - cd ios/ATPKit
            - pod trunk push ATPKit.podspec

使用 pod 发布 SDK 库。

执行 pod trunk push Renderer.podspec 后,我们得到了 Pod 依赖 https://cocoapods.org.cn/pods/Renderer

执行 pod trunk push ATPKit.podspec 后,我们得到了 Pod 依赖 https://cocoapods.org.cn/pods/ATPKit

上述管道脚本因用户权限问题无法在 Bitbucket 中执行,可能需要构建包含 pod 的自 Docker 镜像。只需将 davidthornton/node6-cocoapods 替换为适当的 Docker 镜像即可。