This service provides features for building a custom account system, including registration, logon, logout, account retrieval, Session Manager, human-machine verification, and logon UI customization. The service uses the OAuth 2.0 protocol to help developers integrate their existing account systems into app development.
Initialization
To initialize the SDK, see SDK Initialization.
The Open Account (OA) SDK requires IMSOpenAccountCustom. Integrate the following dependency files: `pod 'IMSOpenAccountCustom','1.1.11'` and `pod 'AlicloudALBBOpenAccount', '3.7.4'`.
Move the XIB file from `IMSOpenAccountCustomResource.bundle` in IMSOpenAccountCustom to the main project.
To set the language, specify a prefix. For example, use the prefix `zh` for Chinese. The languages available for the OA module are the same as those for the SDK. For more information, see Common SDK.
[[IMSiLopOALanguageManage shareInstance] setOpenAccountModuleLanguageWithLanguagePrefix:@"zh"];
Set `[ALBBOpenAccountUIManager sharedInstance].loadNibBundle` to `mainbundle`. Otherwise, an exception might occur.
Built-in accounts
Basic features
Registration
// Import the header files. #import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h> #import <ALBBOpenAccountCloud/ALBBOpenAccountUser.h> // Obtain the account UI service. id<ALBBOpenAccountUIService> uiService = ALBBService(ALBBOpenAccountUIService); // Display the mobile registration window. The presentingViewController displays the logon interface view controller. [uiService presentRegisterViewController:presentingViewController success:^(ALBBOpenAccountSession *currentSession) { // Registration is successful. currentSession contains the current session information. } failure:^(NSError *error) { // This is executed only if the user cancels the registration. }]; // Display the email registration window. The presentingViewController displays the logon interface view controller. [uiService presentEmailRegisterViewController:presentingViewController success:^(ALBBOpenAccountSession *currentSession) { // Registration is successful. currentSession contains the current session information. } failure:^(NSError *error) { // This is executed only if the user cancels the registration. }];Logon
The platform supports two logon methods: username and email. Both methods are available on the logon page.
// Import the header files. #import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h> #import <ALBBOpenAccountCloud/ALBBOpenAccountUser.h> // Obtain the account UI service. id<ALBBOpenAccountUIService> uiService = ALBBService(ALBBOpenAccountUIService); // Display the logon window. The presentingViewController displays the logon interface view controller. [uiService presentLoginViewController:presentingViewController success:^(ALBBOpenAccountSession *currentSession) { // Logon is successful. currentSession contains the current session information. // Obtain the current session ID. NSLog(@"sessionId:%@", currentSession.sessionID); // Obtain the current user information. ALBBOpenAccountUser *currentUser = [currentSession getUser]; NSLog(@"mobile:%@", [currentUser mobile]); NSLog(@"avatarUrl:%@", [currentUser avatarUrl]); NSLog(@"accountId:%@", [currentUser accountId]); NSLog(@"displayName:%@", [currentUser displayName]); } failure:^(NSError *error) { // An error is returned if the logon fails. An error code is also returned if the logon is canceled. }];Log out
// Import the header file. #import <IMSAccount/IMSAccountService.h> // Log out. [[IMSAccountService sharedService] logout];Forgot password
The registration and forgot password features are available on the logon page. No additional development is required.
Close an account
When you close an account, the relationship with the attached device is also removed. For more information, see Close an account.
Modify personal information
Modify a nickname
// Import the header files. #import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h> #import <ALBBOpenAccountCloud/ALBBOpenAccountService.h> [ALBBService(ALBBOpenAccountService) updateAccountProfile:@{@"displayName" : @"name1"} Callback:^(NSError *error) { if (error == nil) { NSLog(@"Nickname modified successfully."); } else { NSLog(@"Failed to modify nickname."); } }];Modify a profile picture
Store the profile picture in the cloud to obtain its URL. Then, use the following code to update the profile picture.
#import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h> #import <ALBBOpenAccountCloud/ALBBOpenAccountService.h> [ALBBService(ALBBOpenAccountService) updateAccountProfile:@{@"avatarUrl" : url} Callback:^(NSError *error) { if (error == nil) { NSLog(@"Profile picture modified successfully."); } else { NSLog(@"Failed to set profile picture."); } }];
Refresh a session
// Import the header file. #import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h> // Obtain the current session. ALBBOpenAccountSession *session = [ALBBOpenAccountSession sharedInstance]; // Refresh the current session. [session refreshSessionIDWithCallback:^(NSString *sid, NSError *err) { // If the operation fails, an error is returned. Otherwise, the new session ID (sid) is returned. }];Retrieve the session ID
// Import the header file. #import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h> ALBBOpenAccountSession *session = [ALBBOpenAccountSession sharedInstance]; NSString *sessionID = session.sessionID;Retrieve user information
// Import the header file. #import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h> // Obtain the current session. ALBBOpenAccountSession *session = [ALBBOpenAccountSession sharedInstance]; if ([session isLogin]) { // Obtain the user information. ALBBOpenAccountUser *user = session.getUser; }Handling logon expiration
For more information, see the Authentication error handling for API requests section in Identity Authentication SDK.
Set the OA language and resource files
Integrate the following dependency files
pod 'IMSOpenAccountCustom', '1.1.11' pod 'AlicloudALBBOpenAccount', '3.7.4'Set the resource path
Move the XIB file from `IMSOpenAccountCustomResource.bundle` in IMSOpenAccountCustom to the main project.
Set the resource path before you call the OA SDK page.
[ALBBOpenAccountUIManager sharedInstance].loadNibBundle = [NSBundle mainBundle];Set multiple languages
Custom method for simple integration
To set the language, specify a prefix. For example, use the prefix `zh` for Chinese or `ko` for Korean.
// Use the default translation resource file. [[IMSiLopOALanguageManage shareInstance] setOpenAccountModuleLanguageWithLanguagePrefix:@"ko"]; // Use your own resource file. // Copy the .lproj file from IMSOpenAccountCustomResource.bundle in IMSOpenAccountCustom, and create a multilingual translation file with the same keys. [[IMSiLopOALanguageManage shareInstance] setOpenAccountModuleLanguageWithLanguagePrefix:@"ko" bundleName:@"xxxx"];The languages available for the OA module are the same as those for the SDK. For more information, see Common SDK.

Advanced customization
// 1. Set the cloud language. For more information about the supported languages, see Common SDK. [[ALBBOpenAccountSDK sharedInstance] setRpcLocale:locale]; // 2. Modify the display language on the XIB file. The default language is Chinese. // a. Copy the content of the .lproj file from ALBBOpenAccount.bundle in ALBBOpenAccountUI, and create a multilingual translation file with the same keys. // b. Set the internationalization file to display. [[ALBBOpenAccountSDK sharedInstance] setLocale:@"zh.lproj"]; // c. Specify the path of the internationalization file. NSString *bundlePath = [NSString stringWithFormat:@"%@/%@.bundle/zh.lproj",[NSBundle mainBundle].bundlePath, bundleName]; [[ALBBOpenAccountSDK sharedInstance] setLocaleBundle:[NSBundle bundleWithPath:bundlePath]]; // d. Set the proxy for each controller in the XIB file. In the proxy method, retrieve the multilingual text for the controls and assign the values. id<ALBBOpenAccountUIService> uiService = ALBBService(ALBBOpenAccountUIService); [uiService setLoginViewDelegate:self]; - (void)loginViewDidLoad:(ALBBOpenAccountLoginViewController *)viewController { viewController.usernameField.placeholder = @"xxx"; // Retrieve the resource and assign the value. viewController.usernameLabel.text = @"xxx"; // Retrieve the resource and assign the value. }
Customize the UI
For more information, see Customize the OA UI for an iOS app.
Third-party accounts
You must initialize the SDK before you connect to a third-party account. For more information about SDK initialization, see SDK initialization.
Import the dependent header files.
#import <ALBBOpenAccountSSO/ALBBOpenAccountSSOSDK.h> #import <IMSAccount/IMSAccountService.h>Implement a custom logon for your account, obtain the AuthCode for OAuth 2.0, and call
ALBBOpenAccountSSOServiceto perform an OAuth authorization logon.For information about how to implement asyncLoginGetAuthCode, see User Account Development Guide.
@implementation IMSAccountThirdViewController - (void)asyncLoginGetAuthCode:(void (^)(NSError * _Nullable error, NSString * _Nullable authCode))completionHandler { // Log on with your own account and obtain the AuthCode through the OAuth 2.0 service. } - (IBAction)onClickLogin:(id)sender { [self asyncLoginGetAuthCode:^(NSError * _Nullable error, NSString * _Nullable authCode) { if (error) { // Handle the error. return; } else { id<ALBBOpenAccountSSOService> ssoService = ALBBService(ALBBOpenAccountSSOService); [ssoService oauthWithThirdParty:authCode delegate:self]; } }]; } @endImplement the callback for the OAuth authorization logon.
@interface IMSAccountThirdViewController () <SSODelegate> @end @implementation IMSAccountThirdViewController - (void)openAccountOAuthError:(NSError *)error Session:(ALBBOpenAccountSession *)session { if (!error) { // Logon is successful. Send a logon success notification. The Identity Authentication SDK listens for this notification to create and manage user identity credentials. NSString *loginNotificationName = [[IMSAccountService sharedService].sessionProvider accountDidLoginSuccessNotificationName]; [[NSNotificationCenter defaultCenter] postNotificationName:loginNotificationName object:nil]; } else { // Handle the logon failure. } } @end