SaltEdge-iOS 4.0.0

SaltEdge-iOS 4.0.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2018年1月

Constantin LunguVladislav Somov维护。



  • SaltEdge

Salt Edge iOS

几个类,帮助您从iOS应用程序与Salt Edge API交互。

需求

iOS 7及以上,ARC。

安装

源代码

克隆此存储库

$ git clone [email protected]:saltedge/saltedge-ios.git

Classes文件夹复制到您的项目中。

使用示例应用连接登录

  1. 运行$ pod install安装依赖项
  2. 请将AppDelegate.m(在中)中的clientIdappSecretcustomerIdentifier常量替换为您的客户ID和相应的App密钥
  3. 运行应用程序

注意:您可以在secrets页面找到您的客户ID和App密钥。

SEWebView

一个小的UIWebView替代品,用于在iOS应用程序中使用Salt Edge Connect

用法

Swift

您也可以在Swift项目中使用SaltEdge iOS SDK。要这样做,请按照安装说明进行操作,并另外创建一个桥接头文件,并将您希望在使用Swift中使用的类导入到该桥接头文件中。

  • 将类和代理文件导入到视图控制器中(仅限于Objective-C)
  • 将一个SEWebView实例添加到视图控制器的视图中,并为web视图设置一个stateDelegate
  • 在代理类中实现SEWebViewDelegate方法
  • 在web视图中加载连接页面
  • 等待并处理SEWebViewDelegate回调

注意:不要在SEWebView上使用delegate属性,因为SEWebView充当代理对象。如果您的类确实需要响应该UIWebView代理方法,只需实现它们,SEWebView实例将把那些消息转发给它的stateDelegate

示例

Objective-C

将类和代理文件导入到您的视图中,让您的视图控制器符合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]]];

Swift

让您的视图控制器符合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))
}

SEAPIRequestManager

一个用于与Salt Edge API交互和查询的便利方法的类。包含获取实体(登录、交易、账户等)的方法,用于通过SEWebView请求连接、重新连接和刷新登录的登录令牌,以及通过REST API连接登录的方法。

用法

在首次使用之前,请先导入管理类并将您的客户端ID和应用程序机密链接到一起。

示例

Objective-C

#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...
    }];
}

Swift

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、应用程序密钥和客户标识符。将 clientIdappSecretcustomerIdentifier 常量设置为您在 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文件。

参考资料

  1. Salt Edge Connect指南
  2. Salt Edge API参考