Yat Partner 集成 iOS 框架
此框架旨在使 Yat 伙伴轻松将 Yat 购买或连接流程集成到他们的应用程序中。
要求
- iOS 13.0+
- Swift 5
安装
使用 Cocoapods
您可以使用 CocoaPods 安装 YatLib
,方法是在 Podfile
中添加它
use_frameworks!
target 'MyApp' do
pod 'YatLib'
end
设置
-
创建您的应用,添加
YatLib
作为pip依赖项,如上所述,然后执行pod install
。 -
YatLib
使用深度链接从Yat网络应用程序返回到应用程序。深度链接的URL方案由Yat开发团队和集成合作伙伴共同协商。按照项目情况设置您的深度链接。- 在项目浏览器中选择您的项目。
- 在
目标
下选择您的应用程序目标。 - 选择
信息
选项卡并展开URL类型
部分。 - 单击
+
按钮,将应用程序的URL方案输入到URL方案
文本框中。
-
打开
SceneDelegate.swift
文件,更新和添加以下功能import UIKit import YatLib final class SceneDelegate: UIResponder, UIWindowSceneDelegate { func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { Yat.configuration = YatConfiguration(appReturnLink: "{app_return_link}", organizationName: "{organization_name}", organizationKey: "{organization_key}") } func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { guard let url = URLContexts.first?.url else { return } Yat.integration.handle(deeplink: url) } // ... rest of the implementation ... }
应用回退链接、组织名称和组织密钥将由Yat开发团队提供。
用法
Yat
是一个集成入口点。它包含配置、样式、集成和与API交互所需的所有工具。配置
要配置集成,您需要向
Yat.configuration
传递新的配置(有关更多信息,请参阅上面设置部分)。样式
可以通过更改存储在
Yat.style
中的值来更改套接字使用的 UI 元素的样式(颜色、字体等)。集成
Yat.integration
提供了便利方法以呈现一个统一的 UI,使用户能够将自己的加密钱包地址连接到 Yat。要显示一个简单的启动界面,您需要
Yat.integration.showOnboarding(onViewController: hostViewController, records: records)
其中
hostViewController
将是负责托管模态界面的UIViewController
,而records
是一个将被附加到用户 Yat 上的YatRecordInput
结构的数组。为了正确处理成功的响应,您只需在
SceneDelagate.swift
中添加以下代码Yat.integration.handle(deeplink: url)
。请参阅上方的“设置”部分以获取更多信息。
API
Yat.api
提供了所有用于直接与 Yat API 进行通信的便利方法。目前,YatLib 提供处理以下 API 调用的方法:GET /emoji_id/{yat}/{symbol}
获取与提供的符号关联的 Yat 的所有记录。
要使用此端点,您应调用以下方法之一
fetchRecords(forYat yat: String, symbol: String, result: @escaping (Result<LookupEmojiIDWithSymbolResponse, APIError>) -> Void)
示例 - 常规请求
Yat.api.fetchRecords(forYat: "👒🍥🍬♐🕌", symbol: "XTR") { result in switch result { case let .success(response): // Handle response case let .failure(error): // Handle failure } }
fetchRecordsPublisher(forYat yat: String, symbol: String) -> AnyPublisher<LookupEmojiIDWithSymbolResponse, APIError>
示例 - 常规请求与Apple的Combine
Yat.api.fetchRecordsPublisher(forYat: "👒🍥🍬♐🕌", symbol: "XTR") .sink { completion in // Handle completion/failure } receiveValue: { response in // Handle response } .store(in: &cancelables)
GET /emoji_id/{yat}/json/{key}
获取与提供的Yat关联的键值存储。根据提供的
dataType
返回不同的数据集。要使用此端点,您应调用以下方法之一
func fetchFromKeyValueStore<T: LoadJsonDataContainer>(forYat yat: String, dataType: T.Type, result: @escaping (Result<LoadJsonResponse<T>, APIError>) -> Void)
示例 - 常规请求
Yat.api.fetchFromKeyValueStore(forYat: "👒🍥🍬♐🕌", dataType: VisualizerFileLocations.self) { result in switch result { case let .success(response): // Handle response case let .failure(error): // Handle failure } }
func fetchFromKeyValueStorePublisher<T: LoadJsonDataContainer>(forYat yat: String, dataType: T.Type) -> AnyPublisher<LoadJsonResponse<T>, APIError>
示例 - 常规请求与Apple的Combine
Yat.api.fetchFromKeyValueStorePublisher(forYat: "👒🍥🍬♐🕌", dataType: VisualizerFileLocations.self) .sink { completion in // Handle completion/failure } receiveValue: { response in // Handle response } .store(in: &cancelables)