许可证 | MIT |
发布最后发布 | 2023 年 11 月 |
由 Luis Sanches,Rob Weber,James Go,Britton Katnich,Yasmeen Taj,Syed Yusuf,Syed Yusuf 维护。
依赖项 | |
MASFoundation | = 2.4.00 |
MAS-Proximity | = 2.4.00 |
MASUI 是 iOS 移动 SDK 的核心 UI 框架,是 CA 移动 API 网关的一部分。它提供实现用户登录对话框、社交登录、一次性密码和近距离登录(二维码和 BLE)的资源,从而节省了开发者构建这些 UI 的时间,同时也为他们提供了一种快速的原型设计应用的方式。
MASUI 框架包含以下功能
欢迎并感谢所有贡献。要了解更多信息,请参阅 贡献指南。
MASUI 支持使用多种方法将库安装到项目中。
要使用 CocoaPods 将 MASUI 集成到您的 Xcode 项目中,在 Podfile 中指定它:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
pod 'MASUI'
然后,从您的项目文件夹的命令提示符中运行以下命令
$ pod install
对于手动安装,您需要在 Xcode 项目中添加 Mobile SDK。请注意,您必须添加 MASFoundation 库。为了完全启用 MAS 功能,按照以下所示安装所有 MAS 库。
如果需要则复制项
。文件->向“项目名称”添加文件
并将 msso_config.json 文件添加到您的项目文件夹中。-ObjC
添加到“其他链接器标志”中。#import <MASFoundation/MASFoundation.h>
#import <MASUI/MASUI.h>
MASUI 库包含图形和 xib 文件以加快开发时间。该库提供以下 UI 组件:
要使用用户登录对话框,将MASUI.framework
和MASUIResources.bundle
拖放到您的项目中。将MASUI库添加到项目后,MASFoundation会自动检测MASUI库的存在,并根据需要处理用户登录。
MASUI提供以下方法来启用或禁用登录对话框。如果MASUI被禁用以处理身份验证,则调用MASUserLoginBlock
以检索用户名和密码。
/**
* Set the handling state of the authentication UI by this library.
*
* @param handle YES if you want the library to enable it, NO if not.
* YES is the default.
*/
+ (void)setWillHandleAuthentication:(BOOL)handle;
当MASFoundation意识到需要用户身份验证或您调用以下方法以显示登录屏幕时,将提示用户登录对话框。
//
// Display the login screen
//
[[MASUser currentUser] presentLoginViewControllerWithCompletion:^(BOOL completed, NSError *error){
}];
要自定义用户登录对话框,您需要MASUI库,并创建自己的登录视图控制器,它继承了MASBaseLoginViewController
。创建自己的用户登录对话框后,您只需设置MASUI库中的默认用户登录屏幕,这样在需要用户身份验证时就会提示自定义登录屏幕。
::: alert danger
重要!不要无故修改MASBaseLoginViewController
的任何属性。这些属性用于内部处理身份验证。修改它们可能导致应用程序出现多种故障。
:::
在实现自定义登录对话框之前,实现以下方法,并调用父类的方法。
- (void)viewWillReload;
调用此方法是在提示用户登录屏幕之前。此方法准备最新认证信息的UI数据源和其他逻辑。
- (void)viewWillReload
{
[super viewWillReload];
//
// Prepare for data source and other logic
//
}
- (void)viewDidReload;
调用此方法是在提示用户登录屏幕之后。此方法重新加载所有UI元素和其他逻辑。
- (void)viewDidReload
{
[super viewDidReload];
//
// Reload all UI elements and logic
//
}
- (void)loginWithUsername:(NSString *)username password:(NSString *)password completion:(MASCompletionErrorBlock)completion;
可以使用提供的用户凭据调用此方法以执行用户认证。请注意,此方法的成功认证不会关闭用户登录屏幕;必须显式调用关闭方法。
//
// On your custom IBAction, or other places to perform authentication
//
- (IBAction)onLoginButtonSelected:(id)sender
{
[self loginWithUsername:@"username" password:@"password" completion:^(BOOL completed, NSError *error){
//
// handle the result
//
}];
}
- (void)loginWithAuthorizationCode:(NSString *)authorizationCode completion:(MASCompletionErrorBlock)completion;
可以使用提供的授权代码调用此方法以执行用户认证。请注意,此方法的成功认证不会关闭用户登录屏幕;必须显式调用关闭方法。
//
// On your custom IBAction or other places to perform authentication
//
- (IBAction)onLoginButtonSelected:(id)sender
{
[self loginWithAuthorizationCode:@"auth_code" completion:^(BOOL completed, NSError *error){
//
// handle the result
//
}];
}
- (void)cancel;
当用户想要取消认证过程或关闭用户登录屏幕时,可以调用此方法。调用此方法将关闭用户登录屏幕。
- (void)cancel
{
[super cancel];
//
// Do what you have to do upon cancel
//
}
- (void)dismissLoginViewControllerAnimated:(BOOL)animated completion: (void (^)(void))completion;
可以在成功认证后或您想要关闭登录屏幕的其他时段调用此方法以关闭用户登录屏幕。
//
// Dismiss the view controller
//
[self dismissLoginViewControllerAnimated:YES completion:nil];
创建自定义登录屏幕后,您必须创建一个视图控制器对象,并使用以下方法将其设置为MASUI库中的默认登录屏幕。
::: alert danger
注意:用户登录对话框视图控制器对象在多次用户登录时被重用。正确组织在用户身份验证前后提供的UI元素的整个生命周期非常重要。
:::
/**
Set the custom login view controller for handling by MASUI library
@param viewController view controller object that inherited MASBaseLoginViewController
*/
+ (void)setLoginViewController:(MASBaseLoginViewController *)viewController;
社交登录功能包含在用户登录对话框中(在上一节中描述)。无需设置即可设置社交登录。
只需将MASUI.framework和MASUIResource.bundle拖放到您的项目中,即可提供会话锁定屏幕。MASFoundation检测到MASUI库的存在,并在API调用时显示会话锁定屏幕。
/**
Display currently set lock screen view controller in MASUI for locked session
@param completion MASCompletionErrorBlock to notify the result of the displaying lock screen.
*/
+ (void)presentSessionLockScreenViewController:(MASCompletionErrorBlock)completion;
您可以使用自定义逻辑来自定义会话锁定和解锁,以及用于品牌化。会话锁定屏幕必须继承自MASViewController(MASUI库)。有关MASFoundation库中指纹会话锁定API的更多信息,请参阅指纹会话锁定部分。
创建自己的屏幕后,只需将 MASUI 库中的默认会话锁定屏幕设置;当您调用显示会话锁定屏幕时,您的屏幕会提示。
/**
Set custom lock screen view controller that inherits MASViewController
@param viewController MASViewController of the lock screen
*/
+ (void)setLockScreenViewController:(MASViewController *)viewController
要使用一次性密码对话框,将 MASUI.framework 和 MASUIResources.bundle 拖放到您的项目中。MASFoundation 会检测到 MASUI 库的存在并处理一次性密码。
MASUI 提供以下方法来启用或禁用一次性密码交付渠道对话框。
/**
* Set the handling state of the OTP authentication UI by this framework.
*
* @param handle YES if you want the framework to enable it, NO if not.
* YES is the default.
*/
+ (void)setWillHandleOTPAuthentication:(BOOL)handle;
如果禁用 MASUI 来处理一次性密码认证,则会调用 MASOTPChannelSelectionBlock 来检索一次性密码交付渠道。
MASUI 提供以下方法来启用或禁用一次性密码对话框。
/**
* Set the handling state of the OTP authentication UI by this framework.
*
* @param handle YES if you want the framework to enable it, NO if not.
* YES is the default.
*/
+ (void)setWillHandleOTPAuthentication:(BOOL)handle;
如果禁用 MASUI 来处理一次性密码认证,则会调用 MASOTPCredentialsBlock 来检索一次性密码。
版权所有(c)2016 CA。保留所有权利。
本软件可根据 MIT 许可证的条款进行修改和分发。
有关详细信息,请参阅LICENSE 文件。