ref |> 处理App进入前台后,在未登录情况下从新预取一次匿名手机号
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing
4 changed files
with
35 additions
and
3 deletions
| @@ -11,6 +11,13 @@ export enum EmitterEventId { | @@ -11,6 +11,13 @@ export enum EmitterEventId { | ||
| 11 | // 跳转首页指定频道,事件id | 11 | // 跳转首页指定频道,事件id |
| 12 | JUMP_HOME_CHANNEL = 4, | 12 | JUMP_HOME_CHANNEL = 4, |
| 13 | 13 | ||
| 14 | - LOCATION = 5 | 14 | + LOCATION = 5, |
| 15 | + | ||
| 16 | + // App回到前台 | ||
| 17 | + APP_ENTER_FOREGROUD = 100, | ||
| 18 | + // App进入后台 | ||
| 19 | + APP_ENTER_BACKGROUD = 101, | ||
| 20 | + | ||
| 21 | + | ||
| 15 | } | 22 | } |
| 16 | 23 |
| @@ -2,6 +2,7 @@ import HuaweiAuth from './utils/HuaweiAuth' | @@ -2,6 +2,7 @@ import HuaweiAuth from './utils/HuaweiAuth' | ||
| 2 | import { JumpInterceptorAction, RouterJumpInterceptor, WDRouterPage } from 'wdRouter' | 2 | import { JumpInterceptorAction, RouterJumpInterceptor, WDRouterPage } from 'wdRouter' |
| 3 | import { BusinessError } from '@kit.BasicServicesKit' | 3 | import { BusinessError } from '@kit.BasicServicesKit' |
| 4 | import { router } from '@kit.ArkUI' | 4 | import { router } from '@kit.ArkUI' |
| 5 | +import { AccountManagerUtils } from 'wdKit/Index' | ||
| 5 | 6 | ||
| 6 | class LoginJumpHandler implements JumpInterceptorAction { | 7 | class LoginJumpHandler implements JumpInterceptorAction { |
| 7 | 8 | ||
| @@ -25,7 +26,13 @@ export class LoginModule { | @@ -25,7 +26,13 @@ export class LoginModule { | ||
| 25 | /// 初始化华为一键登录相关 | 26 | /// 初始化华为一键登录相关 |
| 26 | if (HuaweiAuth.enable) { | 27 | if (HuaweiAuth.enable) { |
| 27 | 28 | ||
| 28 | - HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone() | 29 | + HuaweiAuth.sharedInstance().registerEvents() |
| 30 | + | ||
| 31 | + AccountManagerUtils.isLogin().then((login) => { | ||
| 32 | + if (!login) { | ||
| 33 | + HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone() | ||
| 34 | + } | ||
| 35 | + }) | ||
| 29 | RouterJumpInterceptor.register(WDRouterPage.loginPage, new LoginJumpHandler()) | 36 | RouterJumpInterceptor.register(WDRouterPage.loginPage, new LoginJumpHandler()) |
| 30 | } | 37 | } |
| 31 | 38 |
| 1 | import { authentication, extendService } from '@kit.AccountKit'; | 1 | import { authentication, extendService } from '@kit.AccountKit'; |
| 2 | -import { Logger } from 'wdKit/Index'; | 2 | +import { AccountManagerUtils, EmitterEventId, EmitterUtils, Logger } from 'wdKit/Index'; |
| 3 | import { util } from '@kit.ArkTS'; | 3 | import { util } from '@kit.ArkTS'; |
| 4 | import { DEFAULT } from '@ohos/hypium'; | 4 | import { DEFAULT } from '@ohos/hypium'; |
| 5 | import { BusinessError } from '@kit.BasicServicesKit'; | 5 | import { BusinessError } from '@kit.BasicServicesKit'; |
| @@ -24,6 +24,20 @@ export default class HuaweiAuth { | @@ -24,6 +24,20 @@ export default class HuaweiAuth { | ||
| 24 | return HuaweiAuth.instance | 24 | return HuaweiAuth.instance |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | + registerEvents() { | ||
| 28 | + // 注册用户退出登录,取一次用来下次使用 | ||
| 29 | + EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, ((str?: string) => { | ||
| 30 | + HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone() | ||
| 31 | + })) | ||
| 32 | + EmitterUtils.receiveEvent(EmitterEventId.APP_ENTER_FOREGROUD, ((str?: string) => { | ||
| 33 | + AccountManagerUtils.isLogin().then((login) => { | ||
| 34 | + if (!login) { | ||
| 35 | + HuaweiAuth.sharedInstance().rePrefetchAnonymousPhone() | ||
| 36 | + } | ||
| 37 | + }) | ||
| 38 | + })) | ||
| 39 | + } | ||
| 40 | + | ||
| 27 | // 重新预取手机号(App启动未登录、回前台未登录、和退出登录 时调用提前取号) | 41 | // 重新预取手机号(App启动未登录、回前台未登录、和退出登录 时调用提前取号) |
| 28 | rePrefetchAnonymousPhone() { | 42 | rePrefetchAnonymousPhone() { |
| 29 | this._anonymousPhone = undefined | 43 | this._anonymousPhone = undefined |
| @@ -96,10 +96,14 @@ export default class EntryAbility extends UIAbility { | @@ -96,10 +96,14 @@ export default class EntryAbility extends UIAbility { | ||
| 96 | onForeground(): void { | 96 | onForeground(): void { |
| 97 | // Ability has brought to foreground | 97 | // Ability has brought to foreground |
| 98 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); | 98 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); |
| 99 | + | ||
| 100 | + EmitterUtils.sendEmptyEvent(EmitterEventId.APP_ENTER_FOREGROUD) | ||
| 99 | } | 101 | } |
| 100 | 102 | ||
| 101 | onBackground(): void { | 103 | onBackground(): void { |
| 102 | // Ability has back to background | 104 | // Ability has back to background |
| 103 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); | 105 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); |
| 106 | + | ||
| 107 | + EmitterUtils.sendEmptyEvent(EmitterEventId.APP_ENTER_BACKGROUD) | ||
| 104 | } | 108 | } |
| 105 | } | 109 | } |
-
Please register or login to post a comment