MoneytreeLinkSDK 6.1.0

MoneytreeLinkSDK 6.1.0

Moneytree SDK Distribution 维护。



  • Moneytree 金融科技有限公司

Moneytree Link SDK (iOS)

Moneytree Link SDK 是一个工具箱,您可以将其用于集成 Moneytree 的服务。

SDK 提供了身份验证、存储令牌和启动 Moneytree 网络服务的方法。它还提供了一个用于 LINK Kit 的插件,LINK Kit 是一个完全集成的网络 PFM 解决方案。

ℹ️这里提供的所有代码示例仅供参考。

内容

集成指南

Moneytree Link SDK 包含核心 SDK 和 LINK Kit 模块。

核心 SDK 是提供您对我们所有服务连接的工具,并针对令牌提供一些状态处理选项。

LINK Kit 是一个基于网络的 PFM 服务,作为一个 SDK 模块提供,以简化集成过程。

ℹ️LINK Kit 是 refreshed 和 re-branded 的 Issho Tsucho 名称。

获取SDK

⚠️

  • SDK要求最低部署目标为iOS 9.0。
  • 支持的开发最低Xcode版本为12.0。

我们强烈推荐使用Swift Package Manager。还有其他几种安装方法可用,但我们将通过SPM为您提供最佳支持。

使用Swift Package Manager

  1. 在Xcode中选择文件 > Swift Packages > 添加包依赖
  2. 包URL为https://github.com/moneytree/moneytree-link-ios-sdk。使用最低版本为6.0.0
    • 如果您想使用Beta版本,请选择规则:提交并复制Beta发布提交的完整SHA。

使用CocoaPods

  1. 在项目根目录下运行pod init。这将创建一个Podfile

  2. 将以下内容添加到您的Podfile中。

     pod 'MoneytreeLinkSDK' , '~> 6.0'
    
  3. 在项目根目录下运行以下命令

     pod install --repo-update
    
  4. 打开<project>.xcworkspace。

手动安装SDK

  1. 从最新v6.0.0版本的发布页面此处下载最新的XCFrameworks。
  2. 将下载的.xcframework文件拖放到您的应用程序目标中。 导入 XCFrameworks

配置您的项目

为了连接到Moneytree的服务,您必须在您的应用程序中配置Moneytree客户端ID。您还必须配置自定义URL方案,以便接收来自这些服务的回调。

在您的应用程序的Info.plist文件中

  1. 添加两个条目:MoneytreeLinkDevClientIdMoneytreeLinkClientId。如果您没有客户端ID,请联系Moneytree团队contact the Moneytree team
    1. 这些值是String类型,它们是您开发生产客户端ID。
    2. 开发客户端ID用于在将SDK配置为staging模式时连接到Moneytree Link的staging环境。
    3. 生产客户端ID用于在将SDK配置为production模式时连接到Moneytree Link的production环境。
    4. 更多详细信息请参阅以下内容
  2. 如果还没有,请添加条目URL类型 (CFBundleURLTypes)。
  3. URL类型下添加以下2个条目,以便从SDK接收回调。
  4. 对于开发,请添加mtlink<development-clientId-short><development-clientId-short>是您的开发客户端ID的前5个字符。
  5. 对于生产,请添加mtlink<production-clientId-short>production-clientId-short是您的生产客户端ID的前5个字符。

从Info.plist的示例XML

<key>MoneytreeLinkDevClientId</key>
<string>{your-dev-client-id}</string>
<key>MoneytreeLinkClientId</key>
<string>{your-client-id}</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>mtlink{your-dev-client-id-first-5}</string>
    </array>
  </dict>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>mtlink{your-client-id-first-5}</string>
    </array>
  </dict>
</array>

初始化SDK

我们建议在应用代理中进行SDK初始化,以确保SDK能够在应用程序的生命周期内可用。深度链接和回调也必须在其他应用代理方法中进行配置。您需要在初始化和配置SDK的地方导入MoneytreeLinkCoreKit模块。

创建SDK配置

根据您的授权类型适当地初始化配置对象。然后根据您的需求进行配置。

Swift

// PKCE requires no arguments.
let configuration = MTLConfiguration()

// Code Grant requires the redirect URI of your code grant server.
let configuration = MTLConfiguration(redirectUri: "https://your.server.com/token-exchange-endpoint")

// Set environment to `.staging` for development builds or `.production` for production builds.
configuration.environment = .staging

// Configure the OAuth scopes
// Please refer to the table below for the recommended scopes for specific features
configuration.scopes = [
  MTLClientScopeGuestRead,
  MTLClientScopeAccountsRead,
  MTLClientScopeTransactionsRead
]

Objective-C

// PKCE requires no arguments.
MTLConfiguration *const configuration = [[MTLConfiguration alloc] init];

// Code Grant requires the redirect URI of your code grant server.
MTLConfiguration *const configuration = [[MTLConfiguration alloc] initWithRedirectUri:@"https://your.server.com/token-exchange-endpoint"];

// Set environment to `MTLEnvironmentStaging` for development builds or `MTLEnvironmentProduction` for production builds.
configuration.environment = MTLEnvironmentStaging;

// Configure the OAuth scopes
// Please refer to the table below for the recommended scopes for specific features
configuration.scopes = @[
  MTLClientScopeGuestRead,
  MTLClientScopeAccountsRead,
  MTLClientScopeTransactionsRead
];

配置作用域

所有可用作用域

作用域 描述
MTLClientScopeGuestRead 访问基本账户信息。
MTLClientScopeAccountsRead 访问读取个人账户余额和信息。
MTLClientScopeTransactionsRead 访问读取个人账户交易。
MTLClientScopeTransactionsWrite 访问写入个人账户交易。
MTLClientScopeCategoriesRead 访问读取交易类别。
MTLClientScopeInvestmentAccountsRead 访问读取投资账户余额和信息。
MTLClientScopeInvestmentTransactionsRead 访问读取投资账户交易。
MTLClientScopeRequestRefresh 允许您的应用程序手动请求Moneytree从金融机构检索最新的用户数据。
MTLClientScopePointsRead 访问读取点账户信息。
MTLClientScopePointTransactionsRead 访问读取点账户交易。
MTLClientScopeNotificationsRead 访问读取通知信息。

推荐的功能作用域

功能 推荐的作用域
保险库访问 MTLClientScopeGuestRead, MTLClientScopeAccountsRead, MTLClientScopeTransactionsRead
客户支持 MTLClientScopeGuestRead, MTLClientScopeAccountsRead, MTLClientScopeTransactionsRead

功能的所需作用域

功能 所需的作用域
LINK Kit MTLClientScopeGuestRead, MTLClientScopeAccountsRead, MTLClientScopeTransactionsRead, MTLClientScopeTransactionsWrite, MTLClientScopePointsRead, MTLClientScopeInvestmentAccountsRead, MTLClientScopeInvestmentTransactionsRead

启动SDK

application:didFinishLaunchingWithOptions: 内部

Swift

MTLinkClient(configuration: configuration)

Objective-C

[MTLinkClient clientWithConfiguration:configuration];

配置授权的深度链接

配置应用程序代理以使用项目中在 Info.plist 中配置的URL方案将回调转发给Moneytree LINK SDK。这对于SDK的关键功能(如授权)的正常运行是必需的。

Swift

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
  let moneytreeLinkOpenedURL = MTLApplicationDelegate.shared.application(app, open: url, options: options)

  if moneytreeLinkOpenedURL {
    return true
  } else {
    // Your custom logic, if any, for handling other URL schemes goes here.
  }
}

Objective-C

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
                                         options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
  BOOL moneytreeLinkOpenedURL = [[MTLApplicationDelegate shared] application:app openURL:url options:options];

  if (moneytreeLinkOpenedURL) {
    return YES;
  } else {
    // Your custom logic, if any, for handling other URL schemes goes here.
  }

配置通用链接以便导航

这允许SDK处理来自Moneytree LINK服务器的通用链接。这用于导航到特定的服务,包括

  • 处理Moneytree LINK登录的魔法链接。

  • 打开Moneytree LINK账户设置。

    ⚠️请确保您的 apple-app-site-association 被正确托管,如果您不确定,请联系Moneytree。

Swift

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
  let canMoneytreeHandleUserActivity = MTLApplicationDelegate.shared.application(application, userActivity: userActivity) { error in
    // Handle universal link handling result/error if necessary
  }
  
  // If Moneytree cannot handle this user activity, check if other party can
  return canMoneytreeHandleUserActivity
}

Objective-C

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
  BOOL canMoneytreeHandleUserActivity = [[MTLApplicationDelegate shared] application:application userActivity:userActivity completion:^(NSError *_Nullable error) {
    // Handle universal link handling result/error if necessary
  }];
  
  // If Moneytree cannot handle this user activity, check if other party can
  return canMoneytreeHandleUserActivity
}

配置MTLinkClientDelegate(可选)

如果您的应用需要为特定事件自定义行为,如安全箱关闭或添加新凭证时,请实现此代理。

事件

状态 错误
错误 0 包含错误
安全箱已关闭 1 不包含错误(始终为nil)
通过第三方OAuth添加新凭证 2 不包含错误(始终为nil)

Swift

// Your chosen delegate class (in this example, the app delegate) must conform to MTLinkClientDelegate.
class AppDelegate: MTLinkClientDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let mtLinkClient = MTLinkClient(configuration: configuration)
    
    // Set the delegate.
    mtLinkClient.delegate = self

    return true
  }

  // Implement this delegate method.
  func clientStatusDidChange(to status: MTLinkClientStatus) {
    // Handle status change
  }
}

Objective-C

// In .h file
// Your chosen delegate class (in this example, the app delegate) must conform to MTLinkClientDelegate.
@interface AppDelegate : UIResponder <UIApplicationDelegate, MTLinkClientDelegate>

// In .m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  MTLinkClient *client = [MTLinkClient clientWithConfiguration: configuration];
  
  // Set the delegate.
  client.delegate = self;

  return YES;
}

// Implement this delegate method.
-(void)clientStatusDidChangeToStatus:(MTLinkClientStatus)status {
  // Handle status change
}

使用SDK

变更日志

迁移指南

AwesomeApp 示例设置

故障排除

您可能对 SDK 在应用中的集成有疑问。我们很乐意提供支持。

在此方面,我们希望您能提供以下信息:

  • 环境信息,例如:
    • SDK 版本
    • iOS 版本
    • 任何与您的设置相关的其他信息
  • 一个简单的项目,可以重现您的问题
    • 我们建议您尝试通过修改 AwesomeApp 来重现您的问题。如果无法做到,任何有效的示例都将 suffice。没有实现细节,可能很难找到问题。
  • 您认为可以帮助我们识别问题并帮助您的任何其他信息。