iOS Partner Integration Framework
caution
The integration libraries and documentation for Yat are still in Alpha. They are not yet feature complete, and there are likely bugs in the implementation.
This guide describes the usage of the iOS Yat integration framework for the Yat partners. The integration library provides a simple way for Yat partners to purchase and link Yats from within the partner application.
#
Requirements- iOS 13.0+
- Swift 5
#
Installation#
Using CocoapodsYou can use CocoaPods to install YatLib
by adding it to your Podfile
:
use_frameworks!
target 'MyApp' do pod 'YatLib', '~> 0.2.2'end
#
SetupCreate your app, add
YatLib
as a pod dependency as described above, and do apod install
.YatLib
uses deep links to return from the Yat web application back to the application. The URL scheme of the deep link is agreed upon between the Yat development team and the integration partner. Setup your deep links in your project accordingly.- Select your project in the project browser.
- Select your app target under
Targets
. - Select the
Info
tab and expand theURL types
section. - Click the
+
button, and enter the app's URL scheme into theURL Schemes
text box.
Open
SceneDelegate.swift
file, and update and add the below functions:import UIKitimport 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 ... }
The app return link, organization name, and organization key will be delivered to you by the Yat development team.
Usage
Yat
is an integration entry point. It contains all tools necessary to configure, style, integrate, and interact with API.#
ConfigurationTo configure the integration, you need to pass a new configuration to the
Yat.configuration
(please check the Setup section above for more information).#
StyleYou can change the style (colors, fonts, etc.) of the UI elements used by the framework by changing values stored in
Yat.style
.#
IntegrationYat.integration
exposes convenience methods to present a unified UI that allows the user to connect his crypto wallet address to Yat.To show a simple onboarding overlay, you need to:
Yat.integration.showOnboarding(onViewController: hostViewController, records: records)
Where
hostViewController
is aUIViewController
which will host the modal overlay, andrecords
is an array ofYatRecordInput
structures that will be attached to the user's Yat.To properly handle the response after the success. you simply add:
Yat.integration.handle(deeplink: url)
in
SceneDelagate.swift
. Please check the Setup section above for more information.#
APIYat.api
provides all the convenience methods used to directly communicate with the Yat API. Currently, YatLib provides methods that handle API calls listed below:GET /emoji_id/{yat}/{symbol}
Fetch all records associated with Yat for the provided symbol.
To use this endpoint, you should call one of these methods:
fetchRecords(forYat yat: String, symbol: String, result: @escaping (Result<LookupEmojiIDWithSymbolResponse, APIError>) -> Void)
#
Example - Regular request: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>
#
Example - Regular request with Apple's 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}
Fetch the key-value store associated with provided Yat. It returns a different data set depending on the provided
dataType
.To use this endpoint, you should call one of these methods:
func fetchFromKeyValueStore<T: LoadJsonDataContainer>(forYat yat: String, dataType: T.Type, result: @escaping (Result<LoadJsonResponse<T>, APIError>) -> Void)
#
Example - Regular request: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>
#
Example - Regular request with Apple's Combine:Yat.api.fetchFromKeyValueStorePublisher(forYat: "๐๐ฅ๐ฌโ๐", dataType: VisualizerFileLocations.self) .sink { completion in // Handle completion/failure } receiveValue: { response in // Handle response } .store(in: &cancelables)