测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2018年1月 |
由Constantin Lungu,Vladislav Somov维护。
几个类,帮助您从iOS应用程序与Salt Edge API交互。
iOS 7及以上,ARC。
克隆此存储库
$ git clone [email protected]:saltedge/saltedge-ios.git
将Classes
文件夹复制到您的项目中。
$ pod install
安装依赖项clientId
、appSecret
和customerIdentifier
常量替换为您的客户ID和相应的App密钥注意:您可以在secrets页面找到您的客户ID和App密钥。
一个小的UIWebView
替代品,用于在iOS应用程序中使用Salt Edge Connect。
您也可以在Swift项目中使用SaltEdge iOS SDK。要这样做,请按照安装说明进行操作,并另外创建一个桥接头文件,并将您希望在使用Swift中使用的类导入到该桥接头文件中。
SEWebView
实例添加到视图控制器的视图中,并为web视图设置一个stateDelegate
SEWebViewDelegate
方法SEWebViewDelegate
回调注意:不要在SEWebView
上使用delegate
属性,因为SEWebView
充当代理对象。如果您的类确实需要响应该UIWebView
代理方法,只需实现它们,SEWebView
实例将把那些消息转发给它的stateDelegate
。
将类和代理文件导入到您的视图中,让您的视图控制器符合SEWebViewDelegate
协议。
#import "SEWebView.h"
#import "SEWebViewDelegate.h"
// ... snip ...
@interface MyViewController() <SEWebViewDelegate>
// ... snip ...
实例化一个SEWebView
并将其添加到控制器中
SEWebView* connectWebView = [[SEWebView alloc] initWithFrame:self.view.bounds stateDelegate:self];
[self.view addSubview:connectWebView];
在控制器中实现SEWebViewDelegate
方法
// ... snip ...
- (void)webView:(SEWebView *)webView receivedCallbackWithResponse:(NSDictionary *)response
{
NSString* loginSecret = response[SELoginDataKey][SELoginSecretKey];
NSString* loginState = response[SELoginDataKey][SELoginStateKey];
// do something with the data...
}
- (void)webView:(SEWebView *)webView receivedCallbackWithError:(NSError *)error
{
// handle the error...
}
请注意,您也可以实现UIWebView
的代理方法
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// the method will be called after SEWebView has finished processing it
}
将Salt Edge Connect URL加载到WebView中,您就可以开始了
[connectWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:connectURLString]]];
让您的视图控制器符合SEWebViewDelegate
协议。
class MyViewController : UIViewController, SEWebViewDelegate {
// ... snip ...
}
实例化一个SEWebView
并将其添加到控制器中
let connectWebView = SEWebView.init(frame: self.view.bounds, stateDelegate: self)
self.view.addSubview(connectWebView)
在控制器中实现SEWebViewDelegate
方法
// ... snip ...
func webView(webView: SEWebView!, receivedCallbackWithResponse response: [NSObject : AnyObject]!) {
if let secret = response["data"]?["secret"] as? String,
let state = response["data"]?["state"] as? String {
// do something with the data...
}
}
func webView(webView: SEWebView!, receivedCallbackWithError error: NSError!) {
// handle the error...
}
请注意,您也可以实现UIWebView
的代理方法
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
// the method will be called after SEWebView has finished processing it
}
将Salt Edge Connect URL加载到WebView中,您就可以开始了
if let url = NSURL.init(string: connectURLString) {
self.webView.loadRequest(NSURLRequest.init(URL: url))
}
一个用于与Salt Edge API交互和查询的便利方法的类。包含获取实体(登录、交易、账户等)的方法,用于通过SEWebView
请求连接、重新连接和刷新登录的登录令牌,以及通过REST API连接登录的方法。
在首次使用之前,请先导入管理类并将您的客户端ID和应用程序机密链接到一起。
#import "SEAPIRequestManager.h"
// ... snip ...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[SEAPIRequestManager linkClientId:@"example-client-id" appSecret:@"example-app-secret"];
// ... snip ...
}
使用管理器与提供的API交互
- (void)requestConnectToken
{
SEAPIRequestManager* manager = [SEAPIRequestManager manager];
NSDictionary* params = @{ @"country_code" : @"XO", @"provider_code" : @"paypal_xo", @"return_to" : @"http://example.com", @"customer_id" : @"example-customer-id" };
[manager requestCreateTokenWithParameters:params success:^(NSDictionary* responseObject) {
if (responseObject[kDataKey] && responseObject[kDataKey][kConnectURLKey]) {
NSString* connectURL = responseObject[kDataKey][kConnectURLKey];
// load the connect URL into the SEWebView...
}
} failure:^(SEError* error) {
// handle the error...
}];
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
SEAPIRequestManager.linkClientId("example-client-id", appSecret: "example-app-secret")
// ... snip ...
}
使用管理器与提供的API交互
func requestConnectToken() {
let manager: SEAPIRequestManager = SEAPIRequestManager()
let params = ["country_code" : "XO", "provider_code" : "paypal_xo", "return_to" : "http://example.com", "customer_id" : "customer_id_here"]
manager.requestCreateTokenWithParameters(params, success: {
response in
if let urlString = response["data"]?["connect_url"] as? String {
if let url = NSURL.init(string: urlString) {
// load the connect URL into the SEWebView...
}
}
}, failure: {
error in
// handle the error...
})
}
请提供了一些用于序列化API响应中接收到的对象的模型。这些代表提供者、登录、账户、交易、提供者字段和它们的选项。无论您请求哪种类型的资源,它们都将序列化为Objective-C类。例如,fetchFullTransactionsListForAccountId:loginSecret:success:failure
方法在其成功的回调中有包含SETransaction
实例的NSSet
。
组件内的模型
SEAccount
SELogin
SEError
SEProvider
SEProviderField
SEProviderFieldOption
SETransaction
有关上述模型的补充说明,这些说明未包含在来源文档中,请随时访问[API参考](https://docs.saltedge.com/reference/)。
组件中包含了一些类别和实用类,它们在内部使用,但您如果需要,也可以使用它们。
所有组件都有文档。使用快速文档(Alt+Click)可以快速查看方法或属性的文档。
要运行此处包含的演示应用程序,您需要向演示提供您的客户端ID、应用程序密钥和客户标识符。将 clientId
、appSecret
和 customerIdentifier
常量设置为您在 AppDelegate.m:43-45 中对应的客户端ID和应用程序密钥。
当前SDK版本为 3.2.1,符合Salt Edge API的当前版本。API中任何与以前版本不兼容的更改都将导致SDK的变更。
从3.1.0版本开始,SDK启动SSL锁定功能。这意味着来自SEAPIRequestManager
的每个API请求都将进行SSL证书验证。当前的Salt Edge SSL证书将于2018年5月1日到期,这意味着它将在2018年4月的第一周更新。在SSL证书更新后,SDK将更新以使用新的证书进行SSL锁定。因此,使用旧版SDK将不再可能,因为每个请求都会因旧的SSL证书而失败。Salt Edge的客户端将收到此通知,并将有足够的时间将应用程序更新到SDK的新版本。
参见LICENSE文件。