AMSVaultElement
AMSVaultElement 是 Vaulting Element 的核心类,用于在 iOS 应用中集成 Antom Vaulting Element 独立绑卡组件的主类。商户通过该类完成 SDK 初始化配置、创建绑卡组件、提交绑卡、重置及销毁等操作。
声明
Objective-C
Swift
copy
@interface AMSVaultElement : AMSProductBase访问单例
Objective-C
Swift
copy
@property (class, nonatomic, readonly, strong) AMSVaultElement *shared;
@end名称 | 类型 | 描述 |
shared | AMSVaultElement |
|
实例方法
AMSVaultElement 单例实例提供以下主要方法:
方法名 | 描述 |
用于初始化 SDK 配置。 | |
用于预加载 WebApp 页面和 KYC 页面资源。 | |
用于创建并展示绑卡组件 UI。 | |
用于重置绑卡流程,清除当前状态。 | |
用于销毁实例并释放所有关联资源。 |
属性
Objective-C
Swift
copy
@property (nonatomic, weak, nullable) id<AMSVaultProtocol> paymentDelegate;名称 | 类型 | 描述 |
paymentDelegate | AMSPaymentProtocol? | 支付协议代理,参见 |
使用说明
- 通过
AMSVaultElement.shared访问该实例。 - 调用
createComponent(_:)前需先调用initConfiguration(_:)。 - 所有 UI 相关方法(
createComponent()、reset()、onDestroy())需要从主线程调用。
使用示例
Objective-C
Swift
copy
#import <AMSFoundation/AMSFoundation-Swift.h>
#import <AMSElement/AMSElement-Swift.h>
@interface VaultViewController () <AMSPaymentProtocol>
@end
@implementation VaultViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 1. 创建配置
AMSVaultElementConfiguration *config = [AMSVaultElementConfiguration new];
config.locale = @"en_US";
config.options = @{
@"sandbox": @YES,
@"showLoading": @YES
};
// 2. 初始化 SDK(带回调)
[[AMSVaultElement shared] initConfiguration:config completion:^(AMSStatusResult * _Nonnull result) {
if (result.status == AMSStatusResultTypeSUCCESS) {
NSLog(@"初始化成功");
} else {
NSLog(@"初始化失败: %@", result.error.message);
}
}];
// 3. 设置代理
[AMSVaultElement shared].paymentDelegate = self;
// 4. (可选)预加载资源
[[AMSVaultElement shared] preload];
}
- (void)startVaultingWithSessionData:(NSString *)sessionData {
// 5. 创建绑卡组件(带回调)
[[AMSVaultElement shared] createComponent:sessionData completion:^(AMSStatusResult * _Nonnull result) {
if (result.status == AMSStatusResultTypeSUCCESS) {
NSLog(@"组件创建成功");
}
}];
}
- (void)submitVaulting {
// 6. 提交绑卡
[[AMSVaultElement shared] submit:nil];
}
#pragma mark - AMSPaymentProtocol
- (void)onSubmitPayCallback:(AMSStatusResult * _Nullable)eventResult {
switch (eventResult.status) {
case AMSStatusResultTypeSUCCESS:
NSLog(@"绑卡成功");
break;
case AMSStatusResultTypeFAIL:
NSLog(@"绑卡失败: %@", eventResult.error.message);
break;
case AMSStatusResultTypePROCESSING:
NSLog(@"绑卡处理中");
break;
case AMSStatusResultTypeCANCELLED:
NSLog(@"绑卡已取消");
break;
default:
break;
}
}
- (void)onEventCallback:(NSString * _Nonnull)eventCode eventResult:(AMSEventResult * _Nonnull)eventResult {
NSLog(@"事件回调: %@", eventCode);
}
- (void)dealloc {
[[AMSVaultElement shared] onDestroy];
}
@end