iOS SDK
ATP Kit 是 Atlas Protocol 的一部分组件,与区块链交互以获取 TIE (Targeting Interactive Element)。
此库适用于 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。之后,您只需运行示例演示应用程序,它们将自动构建。
$ 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
CICD
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镜像即可。