xugenyuan

ref |> 将友盟初始化放至主模块的AbilityStage上面调用,解决友盟统计数据下降的问题

https://developer.umeng.com/docs/119267/detail/2712046

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -4,13 +4,14 @@ import { common } from '@kit.AbilityKit';
import { AccountManagerUtils } from '../utils/AccountManagerUtils';
import { UserDataLocal } from '../utils/UserDataLocal';
import { EmitterUtils } from '../utils/EmitterUtils';
import { EmitterEventId } from '../utils/EmitterEventId';
export class UmengStats {
private static _inited = false
// 启动时调用
static preInit(context: common.UIAbilityContext) {
static preInit(context: common.AbilityStageContext) {
// 需在 AppScope/resources/rawfile/umconfig.json 配置key和channel
preInit({
... ... @@ -23,14 +24,23 @@ export class UmengStats {
// 在用户同意隐私政策后再调用此方法
static initAfterAgreeProtocol() {
if (UmengStats._inited) {
return
}
init();
UmengStats._inited = true
UmengStats.onLogin()
UmengStats.event("testHarmony", {"key1": "value1"})
// UmengStats.event("testHarmony", {"key1": "value1"})
EmitterUtils.receiveEvent(EmitterEventId.LOGIN_SUCCESS, () => {
UmengStats.onLogin()
})
EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, () => {
UmengStats.onLogout()
})
}
// TODO: 登录成功调用
static onLogin() {
AccountManagerUtils.isLogin().then((login) => {
if (!login) { return }
... ... @@ -41,7 +51,7 @@ export class UmengStats {
}
})
}
// TODO: 退出登录调用
static onLogout() {
onProfileSignOff()
}
... ...
import AbilityStage from '@ohos.app.ability.AbilityStage';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
import { Configuration } from '@ohos.app.ability.Configuration';
import { SPHelper, UmengStats } from 'wdKit';
export default class MyAbilityStage extends AbilityStage {
onCreate() {
UmengStats.preInit(this.context)
// KV存储
SPHelper.init(this.context);
if (SPHelper.default.getSync('isPrivacy', true)) {
// 同意隐私协议,这里直接初始化。TODO 耗时梳理
UmengStats.initAfterAgreeProtocol()
}
}
onAcceptWant(want: Want): string {
return ""
}
onConfigurationUpdate(newConfig: Configuration): void {
}
onMemoryLevel(level: AbilityConstant.MemoryLevel): void {
}
onDestroy(): void {
}
}
\ No newline at end of file
... ...
... ... @@ -193,7 +193,7 @@ export class StartupManager {
}
private preInitUmentStat() {
UmengStats.preInit(this.context!)
// UmengStats.preInit(this.context!)
}
private initUmengStat() {
Logger.debug(TAG, "App 友盟统计 初始化")
... ...
... ... @@ -4,6 +4,7 @@
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbilityStage.ets",
"deviceTypes": [
"phone",
// "tablet",
... ...