xugenyuan

ref |> 处理App进入前台后,在未登录情况下从新预取一次匿名手机号

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -11,6 +11,13 @@ export enum EmitterEventId {
// 跳转首页指定频道,事件id
JUMP_HOME_CHANNEL = 4,
LOCATION = 5
LOCATION = 5,
// App回到前台
APP_ENTER_FOREGROUD = 100,
// App进入后台
APP_ENTER_BACKGROUD = 101,
}
... ...
... ... @@ -2,6 +2,7 @@ import HuaweiAuth from './utils/HuaweiAuth'
import { JumpInterceptorAction, RouterJumpInterceptor, WDRouterPage } from 'wdRouter'
import { BusinessError } from '@kit.BasicServicesKit'
import { router } from '@kit.ArkUI'
import { AccountManagerUtils } from 'wdKit/Index'
class LoginJumpHandler implements JumpInterceptorAction {
... ... @@ -25,7 +26,13 @@ export class LoginModule {
/// 初始化华为一键登录相关
if (HuaweiAuth.enable) {
HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone()
HuaweiAuth.sharedInstance().registerEvents()
AccountManagerUtils.isLogin().then((login) => {
if (!login) {
HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone()
}
})
RouterJumpInterceptor.register(WDRouterPage.loginPage, new LoginJumpHandler())
}
... ...
import { authentication, extendService } from '@kit.AccountKit';
import { Logger } from 'wdKit/Index';
import { AccountManagerUtils, EmitterEventId, EmitterUtils, Logger } from 'wdKit/Index';
import { util } from '@kit.ArkTS';
import { DEFAULT } from '@ohos/hypium';
import { BusinessError } from '@kit.BasicServicesKit';
... ... @@ -24,6 +24,20 @@ export default class HuaweiAuth {
return HuaweiAuth.instance
}
registerEvents() {
// 注册用户退出登录,取一次用来下次使用
EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, ((str?: string) => {
HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone()
}))
EmitterUtils.receiveEvent(EmitterEventId.APP_ENTER_FOREGROUD, ((str?: string) => {
AccountManagerUtils.isLogin().then((login) => {
if (!login) {
HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone()
}
})
}))
}
// 重新预取手机号(App启动未登录、回前台未登录、和退出登录 时调用提前取号)
rePrefetchAnonymousPhone() {
this._anonymousPhone = undefined
... ...
... ... @@ -96,10 +96,14 @@ export default class EntryAbility extends UIAbility {
onForeground(): void {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
EmitterUtils.sendEmptyEvent(EmitterEventId.APP_ENTER_FOREGROUD)
}
onBackground(): void {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
EmitterUtils.sendEmptyEvent(EmitterEventId.APP_ENTER_BACKGROUD)
}
}
... ...