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
- 在Xcode中选择
文件 > Swift Packages > 添加包依赖
。 - 包URL为
https://github.com/moneytree/moneytree-link-ios-sdk
。使用最低版本为6.0.0
。- 如果您想使用Beta版本,请选择
规则:提交
并复制Beta发布提交的完整SHA。
- 如果您想使用Beta版本,请选择
使用CocoaPods
-
在项目根目录下运行
pod init
。这将创建一个Podfile
。 -
将以下内容添加到您的
Podfile
中。pod 'MoneytreeLinkSDK' , '~> 6.0'
-
在项目根目录下运行以下命令
pod install --repo-update
-
打开
<project>
.xcworkspace。
手动安装SDK
- 从最新v6.0.0版本的发布页面此处下载最新的XCFrameworks。
- 将下载的
.xcframework
文件拖放到您的应用程序目标中。
配置您的项目
为了连接到Moneytree的服务,您必须在您的应用程序中配置Moneytree客户端ID。您还必须配置自定义URL方案,以便接收来自这些服务的回调。
在您的应用程序的Info.plist
文件中
- 添加两个条目:
MoneytreeLinkDevClientId
和MoneytreeLinkClientId
。如果您没有客户端ID,请联系Moneytree团队contact the Moneytree team。- 这些值是
String
类型,它们是您开发和生产客户端ID。 - 开发客户端ID用于在将SDK配置为
staging
模式时连接到Moneytree Link的staging
环境。 - 生产客户端ID用于在将SDK配置为
production
模式时连接到Moneytree Link的production
环境。 - 更多详细信息请参阅以下内容。
- 这些值是
- 如果还没有,请添加条目
URL类型
(CFBundleURLTypes)。 - 在
URL类型
下添加以下2个条目,以便从SDK接收回调。 - 对于开发,请添加
mtlink<development-clientId-short>
。<development-clientId-short>
是您的开发客户端ID的前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。没有实现细节,可能很难找到问题。
- 您认为可以帮助我们识别问题并帮助您的任何其他信息。