CoinySDK 2.0.4

CoinySDK 2.0.4

Kemal Kocabiyik 维护。



CoinySDK 2.0.4

Coiny iOS SDK

CoinySDK 允许您在 iOS 应用程序内买卖加密货币。

安装

要安装 SDK,请打开您的 Podfile 并输入

pod 'CoinySDK'

身份验证

Coiny SDK 允许您使用 OAuth2 身份验证进行身份验证。这意味着您有权管理授权给您应用程序的其他人的账户。

入门

首先,您需要从 Coiny 获取 API 密钥和 API 密码。要将 API 密钥和密码添加到您的应用程序中

  1. 打开您的 AppDelegate 并添加以下内容

Coiny.initialize(appId: "your-app-id")

如果您想在沙盒环境中进行测试

Coiny.initialize(appId: "your-app-id", isDevelopment: true)

  1. 要授权用户使用您的应用程序

Coiny.login(presentingViewController: self, delegate: self)

您可以在用户点击按钮或其他任何东西时调用此方法。有两个代理方法会通知您用户是否已认证。

public protocol CoinyLoginViewDelegate : AnyObject {
	func coinyDidLoggedIn() -> Void
	func coinyLoginDidFail(error : Error?) -> Void
}

制作 API 调用

调用 Get 方法

假设您的应用程序有walllets:read权限,并且用户已经授权了该应用程序。您可以调用API并获取响应,有两种不同的样式。

CoinyApiRequest.createRequest(path: "wallets", 
						parameters: nil, 
						httpMethod: "GET", 
						completionHandler: { (data : [String:Any]) in
			print(data)
		} ,failureHandler :{ (error) in

		})

上面的示例是两种返回包含用户钱包响应的字典样式之一。

CoinySDK 包含API返回的所有强类型响应模型。因此,您可以像以下这样更改请求

CoinyApiRequest.createRequest(path: "wallets", 
						parameters: nil, 
						httpMethod: "GET", 
						completionHandler: { (data : ResponseWrapper<Array<WalletResponse>> ) in
			print(data)
		} ,failureHandler :{ (error) in

		})

传入的响应将被自动转换为 data 对象类型。所有请求/响应模型都实现了 Codable 协议,因此 ApiRequest 能够将响应转换为强类型类。

调用 POST/PUT/DELETE 方法

就像调用 Get 请求一样,您可以使用相同的模式调用所有其他方法。例如,要购买比特币,应该调用以下方法。

CoinyApiRequest.createRequest(path: "orders/buy", 
						parameters: ["pair" : "btc-try" , "price" : 34000 , "orderType" : "Market" , "quantity" : 0] // quantity not needed for market buy order 
						httpMethod: "POST", 
						completionHandler: { (data : ResponseWrapper<Array<TransactionResponse>> ) in // will return an array of transactions because there are at least 2 transaction will occur. 1 is fee transaction, the other is buy transaction
			print(data)
		} ,failureHandler :{ (error) in

		})

就像上面一样,您也可以使用强类型对象作为参数。

let orderRequest = OrderRequest(pair: "btc-try", 
								orderType: .Market, 
								quantity: 0, price: 10000)

CoinyApiRequest.createRequest(path: "orders/buy", 
						parameters: orderRequest // instead of dictionary i used strongly typed class
						httpMethod: "POST", 
						completionHandler: { (data : ResponseWrapper<Array<TransactionResponse>> ) in // will return an array of transactions because there are at least 2 transaction will occur. 1 is fee transaction, the other is buy transaction
			print(data)
		} ,failureHandler :{ (error) in

		})

待办事项

  • 详细模型描述
  • 在应用中获取 access_token
  • 深度链接
  • 处理错误消息。
  • 处理被撤销的访问。
  • 调试模式。