This topic describes how to improve the success rate and user experience of the number authentication feature. It also provides sample code.
You must call the API operations as described below to ensure compliance and a high success rate for the number authentication feature.
Call flow
Authenticate on startup (pre-initialization): Call the
setAuthSDKInfooperation during application startup to complete authentication initialization. This prevents stuttering or failures caused by initialization delays during logon.iOS: Call the operation in the
didFinishLaunchingWithOptionsmethod ofAppDelegate. One-click logon authentication initialization API | Native number verification authentication initialization APIAndroid: Call the operation in the
onCreate()method of yourApplicationclass. One-click logon authentication initialization API | Native number verification authentication initialization APIHarmony: Call the operation in the
onCreate()method ofUIAbility. One-click logon authentication initialization API | Native number verification authentication initialization API
When to call the one-click logon feature: When you need to initiate one-click logon, call the relevant API operations to execute the logon flow.
Call examples
iOS authentication call example
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/**
* Set the key information for ATAuthSDK.
* Maintain this information on your own server.
* For best results, call this at the application entry point.
*/
[[TXCommonHandler sharedInstance] setAuthSDKInfo:@"Your key" complete:^(NSDictionary * _Nonnull resultDic) {
// Callback processing. Example omitted.
}];
}Android authentication call example
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
/* Set the key information for ATAuthSDK. Maintain this information on your own server. For best results, call this at the application entry point. */
final PhoneNumberAuthHelper authHelper = PhoneNumberAuthHelper.getInstance(this, new TokenResultListener() {
@Override
public void onTokenSuccess(String ret) {
}
@Override
public void onTokenFailed(String ret) {
}
});
authHelper.getReporter().setLoggerEnable(true);
authHelper.setAuthSDKInfo('Your key');
}
}
Harmony authentication call example
export default class DemoAbility extends UIAbility {
helper:PhoneNumberAuthHelper|undefined
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
/* Set the key information for ATAuthSDK. Maintain this information on your own server. For best results, call this at the application entry point. */
class TokenListener implements TokenResultListener{
onSuccess(msg: string): void {
console.log("numberauth:success:"+msg)
const result:object=JSON.parse(msg)
const code=result['_code']+''
const token=result['_token']+''
if(code=="600000"){
}
}
onFailure(ret: string): void {
console.log("numberauth:failure:"+ret)
}
}
let listener=new TokenListener()
this.helper=PhoneNumberAuthHelper.getInstance(getContext(this),listener)
this.helper?.checkEnvAvailable(1)
this.helper?.setAuthSDKInfo('Your key')
}
}