xugenyuan

ref |> 新增个推推送接入

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -48,4 +48,8 @@ export class SpConstants{
//游客状态下首次评论时间
static FIRSTCOMMENTTIME = 'firstCommentTime'
static TOURIST_NICK_NAME = 'touristNickName'
// 个推推送
static GETUI_PUSH_CID = "cid"
static GETUI_PUSH_DEVICE_TOKEN = "deviceToken"
}
\ No newline at end of file
... ...
... ... @@ -807,4 +807,9 @@ export class HttpUrlUtils {
let url = HttpUrlUtils.getHost() + "/api/rmrb-user-center/common/user/c/device/push";
return url;
}
}
\ No newline at end of file
static getUploadPushInfoUrl() {
let url = HttpUrlUtils.getHost() + "/api/rmrb-contact/contact/zh/c/push/device"
return url
}
}
... ...
... ... @@ -12,4 +12,6 @@ export { ProcessUtils } from './src/main/ets/utils/ProcessUtils'
export { AssignChannelParam } from './src/main/ets/utils/HomeChannelUtils';
export { RouterJumpInterceptor, JumpInterceptorAction } from './src/main/ets/router/RouterJumpInterceptor'
\ No newline at end of file
export { RouterJumpInterceptor, JumpInterceptorAction } from './src/main/ets/router/RouterJumpInterceptor'
export { AppInnerLink } from './src/main/ets/utils/AppInnerLink'
... ...
import { url } from '@kit.ArkTS'
import App from '@system.app'
import { Logger } from 'wdKit/Index'
const TAG = "AppInnerLink"
export class AppInnerLink {
static readonly INNER_LINK_PROTCOL = "rmrbapp:"
static readonly INNER_LINK_HOSTNAME = "rmrb.app"
static readonly INNER_LINK_PATHNAME = "openwith"
// 内链跳转
// 内链地址例如:rmrbapp://rmrb.app/openwith?type=article&subType=h5_template_article&contentId=30000762651&relId=500000038702&skipType=1&relType=1
static jumpWithLink(innerLink: string) {
let params = AppInnerLink.parseParams(innerLink)
if (!params) {
Logger.info(TAG, "跳转无效的链接地址 " + innerLink)
return
}
switch (params.skipType) {
case 1: {
AppInnerLink.jumpParams(params)
break
}
case 2: {
AppInnerLink.jumpNoParams(params)
break
}
case 3: {
AppInnerLink.jumpAppH5(params)
break
}
case 4: {
AppInnerLink.jumpOutH5(params)
break
}
case 5: {
AppInnerLink.jumpThirdApp(params)
break
}
default: {
Logger.info(TAG, "跳转无效的链接地址 " + innerLink)
}
}
}
private static jumpParams(params: InnerLinkParam) {
}
private static jumpNoParams(params: InnerLinkParam) {
}
private static jumpAppH5(params: InnerLinkParam) {
}
private static jumpOutH5(params: InnerLinkParam) {
}
private static jumpThirdApp(params: InnerLinkParam) {
}
static parseParams(link: string) : InnerLinkParam | undefined {
const that = url.URL.parseURL(link)
if (that.protocol !== AppInnerLink.INNER_LINK_PROTCOL) {
return
}
if (that.hostname !== AppInnerLink.INNER_LINK_HOSTNAME) {
return
}
if (that.pathname !== AppInnerLink.INNER_LINK_PATHNAME) {
return
}
let obj = {} as InnerLinkParam
const params = that.params
obj.type = params.get("type") as string
obj.subType = params.get("subType") as string
obj.contentId = params.get("contentId") as string
obj.relId = params.get("relId") as string
obj.relType = params.get("relType") as string
obj.pageId = params.get("pageId") as string
obj.url = params.get("url") as string
obj.activityId = params.get("activityId") as string
obj.activityType = params.get("activityType") as string
obj.creatorId = params.get("creatorId") as string
obj.firstChannelId = params.get("firstChannelId") as string
obj.skipType = Number(params.get("skipType"))
obj.isLogin = params.get("isLogin") as string
return obj
}
}
interface InnerLinkParam {
type?: string,
subType?: string,
contentId?: string,
relId?: string,
relType?: string
pageId?: string,
url?: string,
activityId?: string,
activityType?: string,
creatorId?: string,
firstChannelId?: string,
skipType: number,
isLogin?: string,
}
\ No newline at end of file
... ...
... ... @@ -2,4 +2,5 @@ export { add } from "./src/main/ets/utils/Calc"
export { HWLocationUtils } from './src/main/ets/location/HWLocationUtils'
export { WDPushNotificationManager } from "./src/main/ets/notification/WDPushNotificationManager"
\ No newline at end of file
// export { WDPushNotificationManager } from "./src/main/ets/notification/WDPushNotificationManager"
export { GetuiPush } from "./src/main/ets/getuiPush/GetuiPush"
\ No newline at end of file
... ...
... ... @@ -7,10 +7,12 @@
"license": "Apache-2.0",
"packageType": "InterfaceHar",
"dependencies": {
"library": "file:./src/main/ets/getuiPush/GTSDK-1.0.1.0.har",
"wdConstant": "file:../../commons/wdConstant",
"wdLogin": "file:../../features/wdLogin",
"wdKit": "file:../../commons/wdKit",
"wdBean": "file:../../features/wdBean",
"wdRouter": "file:../../commons/wdRouter",
"wdNetwork": "file:../../commons/wdNetwork"
}
}
\ No newline at end of file
... ...
import { common, Want } from '@kit.AbilityKit';
import PushManager, {
BindAliasCmdMessage,
GTCmdMessage, GTNotificationMessage, GTTransmitMessage, PushConst,
SetTagCmdMessage,
Tag,
UnBindAliasCmdMessage } from 'library';
import { AppUtils, DeviceUtil, EmitterEventId, EmitterUtils, Logger, SPHelper } from 'wdKit/Index';
import { HostEnum, HostManager, HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork/Index';
import { notificationManager } from '@kit.NotificationKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { SpConstants } from 'wdConstant/Index';
import { PushContentBean, PushContentParser } from './PushContentParser';
const TAG = "GetuiPush"
export class GetuiPush {
private static GETUI_APPID_ONLINE = "sMkzgp09Ov82nU1MGk7Ae6"
private static GETUI_APPID_TEST = "ZMi5AAXYHE84VN9p55YpW2"
private readonly ALIAS_SN_USERID = "userID"
private readonly TAG_SN_TAG = "tag1"
private readonly TAG_PD_ZH = "peopledaily_zh"
private cid: string = ""
private deviceToken: string = ""
private currentUserId = ""
private lastPushContent?: PushContentBean
private initialed = false
private constructor() {
}
private static manager: GetuiPush
static sharedInstance() : GetuiPush {
if (!GetuiPush.manager) {
GetuiPush.manager = new GetuiPush()
}
return GetuiPush.manager
}
init(context: common.UIAbilityContext) {
const isOnlineEnv = HostManager.getHost() === HostEnum.HOST_PRODUCT
PushManager.initialize({
appId:isOnlineEnv ? GetuiPush.GETUI_APPID_TEST : GetuiPush.GETUI_APPID_TEST,
context: context,
onSuccess: (cid:string) => {
Logger.debug(TAG, "个推SDK初始化成功,cid = " + cid)
this.initialed = true
this.cid = cid
this.registerEvents()
this.checkSetup()
},
onFailed: (error:string) => {
Logger.error(TAG, "个推SDK初始化失败,error = " + error)
}
})
}
async requestEnableNotifications(context: common.UIAbilityContext) : Promise<boolean> {
let enabled = await notificationManager.isNotificationEnabled()
if (!enabled) {
try {
await notificationManager.requestEnableNotification(context)
enabled = true
} catch (err) {
Logger.error(TAG, "请求通知权限报错: " + JSON.stringify(err))
let error = err as BusinessError
if (error.code == 1600004) {
Logger.error(TAG, "请求通知权限 - 用户已拒绝")
}
}
}
Logger.info(TAG, "推送 enabled " + enabled)
return enabled
}
checkSetup() {
if (!this.initialed) { return }
if (HttpUtils.isLogin()) {
const userId = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
this.currentUserId = userId
this.setAlias(true, userId)
}
let tags = [this.TAG_PD_ZH, AppUtils.getAppVersionCode()]
this.setTags(tags)
}
// 默认是开启的
switchPush(turnOn: boolean) {
turnOn ? PushManager.turnOnPush() : PushManager.turnOffPush()
}
registerEvents() {
// 登录和退出
EmitterUtils.receiveEvent(EmitterEventId.LOGIN_SUCCESS, () => {
const userId = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
this.currentUserId = userId
this.setAlias(true, userId)
})
EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, () => {
if (this.currentUserId.length) {
this.setAlias(false, this.currentUserId)
}
})
PushManager.setPushCallback({
// cid
onReceiveClientId: (clientId: string) => {
Logger.debug(TAG, "推送 接收到 clientId = " + clientId)
this.cid = PushManager.getClientId()
SPHelper.default.save(SpConstants.GETUI_PUSH_CID, this.cid)
this.uploadPushInfo(this.cid)
},
//接收⼚商token
onReceiveDeviceToken: (deviceToken:string) => {
Logger.debug(TAG, "推送 deviceToken = " + deviceToken)
this.deviceToken = deviceToken;
SPHelper.default.save(SpConstants.GETUI_PUSH_DEVICE_TOKEN, this.deviceToken)
},
// cid 离线上线通知
onReceiveOnlineState: (onLine:boolean) => {
Logger.debug(TAG, "推送 onLine State = " + onLine)
},
//命令相应回复
onReceiveCommandResult: (result: GTCmdMessage) => {
Logger.debug(TAG, "推送 Cmd Message = " + JSON.stringify(result))
this.dealWithCmdMessage(result)
},
//sdk 收到透传消息
onReceiveMessageData: (message: GTTransmitMessage) => {
Logger.debug(TAG, "推送 透传 Message = " + JSON.stringify(message))
this.dealWithTransmitMessage(message)
},
//通知到达回调
onNotificationMessageArrived: (message: GTNotificationMessage) => {
Logger.debug(TAG, "推送 通知到达回调 " + JSON.stringify(message))
},
//通知点击回调, 需要配合PushManager.setClickWant(want)使⽤
onNotificationMessageClicked: (message: GTNotificationMessage) => {
Logger.debug(TAG, "推送 通知 点击 回调 " + JSON.stringify(message))
},
})
}
setAlias(bind: boolean, alias: string, sn: string = this.ALIAS_SN_USERID) {
if (!this.initialed) { return }
if (bind) {
Logger.debug(TAG, "推送 绑定别名 " + alias)
PushManager.bindAlias(alias, sn)
} else {
Logger.debug(TAG, "推送 解绑别名 " + alias)
PushManager.unBindAlias(alias, true, sn)
}
}
setTags(tags: string[], sn: string = this.TAG_SN_TAG) {
if (!this.initialed) { return }
Logger.debug(TAG, "推送 设置标签 " + tags)
PushManager.setTag(tags.map((tag) => {
return new Tag().setName(tag)
}), sn)
}
setBadgeNumber(number: number) {
Logger.debug(TAG, "推送 设置角标 " + number)
PushManager.setBadgeNum(number)
}
// 接收推送数据,包括启动和二次点击拉起
// 参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/push-dev-0000001727885258
onWant(want: Want) {
this.onNewWant(want, true)
}
onNewWant(want: Want, startup: boolean = false) {
Logger.debug(TAG, "want: " + JSON.stringify(want))
this.lastPushContent = undefined
let pushContent = PushContentParser.getPushLinkFromWant(want)
if (pushContent && pushContent.isPush) {
Logger.debug(TAG, "接收到推送: " + JSON.stringify(want.parameters))
this.lastPushContent = pushContent
if (this.initialed) {
this.comsumeLastPushContent()
}
}
}
// 首次进入主页,即可解析跳转推送
onReachMainPage() {
if (this.initialed) {
this.comsumeLastPushContent()
} else {
this.lastPushContent = undefined
}
}
comsumeLastPushContent() {
if (!this.lastPushContent) {
return
}
if (this.lastPushContent.online) {
if (this.lastPushContent.want) {
Logger.debug(TAG, "推送 回执: " + this.lastPushContent.want)
PushManager.setClickWant(this.lastPushContent.want)
}
}
if (this.lastPushContent.pushLink) {
Logger.debug(TAG, "跳转对应页面: " + this.lastPushContent.pushLink)
PushContentParser.jumpWithPushLink(this.lastPushContent.pushLink)
}
this.lastPushContent = undefined
}
private dealWithCmdMessage(result: GTCmdMessage) {
let action: Number = result.action;
if (action === PushConst.BIND_ALIAS_RESULT) {
let bindAliasCmdMessage = result as BindAliasCmdMessage;
/* code 结果说明
0:成功
10099:SDK 未初始化成功
30001:绑定别名失败,频率过快,两次调⽤的间隔需⼤于 1s
30002:绑定别名失败,参数错误
30003:当前 cid 绑定别名次数超限
30004:绑定别名失败,未知异常
30005:绑定别名时,cid 未获取到
30006:绑定别名时,发⽣⽹络错误
30007:别名⽆效
30008:sn ⽆效 */
let code = bindAliasCmdMessage.code
if (code == 0) {
Logger.debug(TAG, "推送 Cmd BindAlias 成功 " + bindAliasCmdMessage.sn)
} else {
Logger.debug(TAG, "推送 Cmd BindAlias 失败 "
+ ",sn = "+bindAliasCmdMessage.sn
+ ",clinetId = "+bindAliasCmdMessage.clientId
+ ",pkgname = "+bindAliasCmdMessage.pkgName
+ ",appId = "+bindAliasCmdMessage.appId
+ ",action = "+result.action
+ ",code ="+bindAliasCmdMessage.code)
}
} else if (action === PushConst.UNBIND_ALIAS_RESULT) {
let unBindAliasCmdMessage = result as UnBindAliasCmdMessage
/* code 结果说明
0:成功
10099:SDK 未初始化成功
30001:解绑别名失败,频率过快,两次调⽤的间隔需⼤于 1s
30002:解绑别名失败,参数错误
30003:当前 cid 解绑别名次数超限
30004:解绑别名失败,未知异常
30005:解绑别名时,cid 未获取到
30006:解绑别名时,发⽣⽹络错误
30007:别名⽆效
30008:sn ⽆效*/
let code = unBindAliasCmdMessage.code
if (code == 0) {
Logger.debug(TAG, "推送 Cmd UnBindAlias 成功 " + unBindAliasCmdMessage.sn)
} else {
Logger.debug(TAG, "推送 Cmd UnBindAlias 失败 "
+ ",sn = "+unBindAliasCmdMessage.sn
+ ",clinetId = "+unBindAliasCmdMessage.clientId
+ ",pkgname = "+unBindAliasCmdMessage.pkgName
+ ",appId = "+unBindAliasCmdMessage.appId
+ ",action = "+result.action
+ ",code ="+unBindAliasCmdMessage.code)
}
} else if (action === PushConst.SET_TAG_RESULT) {
let setTagCmdMessage = result as SetTagCmdMessage
/* code 值说明
0:成功
10099:SDK 未初始化成功
20001:tag 数量过⼤(单次设置的 tag 数量不超过 100)
20002:调⽤次数超限(默认⼀天只能成功设置⼀次)
20003:标签重复
20004:服务初始化失败
20005:setTag 异常
20006:tag 为空
20007:sn 为空
20008:离线,还未登陆成功
20009:该 appid 已经在⿊名单列表(请联系技术⽀持处理)
20010:已存 tag 数⽬超限
20011:tag 内容格式不正确 */
let code = setTagCmdMessage.code
if (code == 0) {
Logger.debug(TAG, "推送 Cmd SetTag 成功 " + setTagCmdMessage.sn)
} else {
Logger.debug(TAG, "推送 Cmd SetTag 失败 "
+ ",sn = "+setTagCmdMessage.sn
+ ",clinetId = "+setTagCmdMessage.clientId
+ ",pkgname = "+setTagCmdMessage.pkgName
+ ",appId = "+setTagCmdMessage.appId
+ ",action = "+result.action
+ ",code ="+setTagCmdMessage.code)
}
}
}
private dealWithTransmitMessage(message: GTTransmitMessage) {
// const taskid = message.taskId
// const messageId = message.messageId
// /* 上报个推透传消息的展示回执。如果透传消息本地创建通知栏消息“展示”了,则调⽤此⽅法上报。
// */
// int gtactionid = 60001;//gtactionid传⼊60001表示个推渠道消息展示了
// boolean result = PushManager.sendFeedbackMessag(taskid, messageid, gtactionid);
// /**
// * 上报个推透传消息的点击回执。如果透传消息本地创建通知栏消息“点击”了,则调⽤此⽅法上报。
// */
// int gtactionid = 60002;//gtactionid传⼊60002表示个推渠道消息点击了
// boolean result = PushManager.sendFeedbackMessage(taskid, messageid, gtactionid);
}
private uploadPushInfo(cid: string) {
const url = HttpUrlUtils.getUploadPushInfoUrl()
let bean: Record<string, string | number> = {}
bean["deviceId"] = DeviceUtil.clientId()
bean["cid"] = cid
bean["userId"] = SPHelper.default.getSync(SpConstants.USER_ID, "") as string
bean["appVersion"] = AppUtils.getAppVersionName()
bean["platform"] = 3
HttpBizUtil.post<ResponseDTO<string>>(url, bean).then((data) => {
Logger.debug(TAG, "上传cid成功" + JSON.stringify(data))
}).catch((e: BusinessError) => {
Logger.debug(TAG, "上传cid失败" + JSON.stringify(e))
})
}
}
\ No newline at end of file
... ...
import Want from '@ohos.app.ability.Want';
import { Logger } from 'wdKit/Index';
import { JSON } from '@kit.ArkTS';
import { AppInfo } from '@mpaas/framework';
import { AppInnerLink } from 'wdRouter/Index';
export interface PushContentBean {
isPush: boolean // 是否为推送数据
want?: Want // want参数 (用来在消费时,回执)
online: boolean // 解析want,是否为在线消息(在线走的是个推通道,离线走的是华为厂商通道)
pushLink?: string // 解析want,对应pushLink参数
}
/*
* */
export class PushContentParser {
private static LAUNCH_PARAM_GETUI_DATA = "gtdata"
private static LAUNCH_PARAM_GETUI_TASKID = "taskid"
private static LAUNCH_PARAM_GETUI_NOTIFYID = "_push_notifyid"
private static PUSH_PARAM_PUSH_LINK = "pushLink"
static getPushLinkFromWant(want: Want) : PushContentBean {
// 个推在线消息
if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_DATA]) {
/*
{
"age": 12,
"gtdata": {
"actionid": "10010",
"appid": "ZMi5AAXYHE84VN9p55YpW2",
"bigStyle": 0,
"checkpackage": "com.peopledailychina.hosactivity",
"content": "通知内容444",
"feedbackid": "0",
"isFloat": false,
"messageid": "44fd0876c9834214a6b7032b35d9826b",
"notifID": 62288,
"notifyStyle": 0,
"payload": "",
"taskid": "TEST_0516_03a84918e7df6191502497ed2cbef384",
"title": "测试通知444",
"wantUri": "{\"deviceId\":\"\",\"bundleName\":\"com.peopledailychina.hosactivity\",\"abilityName\":\"EntryAbility\",\"uri\":\"rmrbapp://rmrb.app:8080/openwith\",\"action\":\"com.test.pushaction\",\"parameters\":{\"pushLink\":\"Getui\",\"age\":12}}"
},
"isCallBySCB": false,
"moduleName": "phone",
"pushLink": "Getui",
"ohos.aafwk.param.callerAbilityName": "",
"ohos.aafwk.param.callerBundleName": "com.ohos.sceneboard",
"ohos.aafwk.param.callerPid": 44239,
"ohos.aafwk.param.callerToken": 537702494,
"ohos.aafwk.param.callerUid": 20020018,
"specifyTokenId": 537063794
}
},*/
let gtData = want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_DATA] as Record<string, string | number | object>
if (gtData[PushContentParser.LAUNCH_PARAM_GETUI_TASKID] != undefined) {
let json = JSON.parse(gtData["wantUri"] as string) as Record<string, string | number>
if (json && json[PushContentParser.PUSH_PARAM_PUSH_LINK] != null) {
const pushLink = json[PushContentParser.PUSH_PARAM_PUSH_LINK] as string
return {
isPush: true, online: true, pushLink: pushLink, want: want
}
}
}
}
/*
{
"deviceId": "",
"bundleName": "com.peopledailychina.hosactivity",
"abilityName": "EntryAbility",
"moduleName": "phone",
"uri": "rmrbapp://rmrb.app:8080/openwith",
"type": "",
"flags": 0,
"action": "com.test.pushaction",
"parameters": {
"_push_notifyid": 1,
"age": 12, // 自定义
"debugApp": false,
"isCallBySCB": false,
"moduleName": "phone",
"pushLink": "Getui", // 自定义
"ohos.aafwk.param.callerAbilityName": "PushServiceInnerAbility",
"ohos.aafwk.param.callerBundleName": "com.huawei.hms.pushservice",
"ohos.aafwk.param.callerPid": 22808,
"ohos.aafwk.param.callerToken": 537908725,
"ohos.aafwk.param.callerUid": 20004,
"ohos.dlp.params.sandbox": false
},
"entities": [
]
* */
// 离线消息,华为直接推送
if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_NOTIFYID]) {
if (want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK]) {
let pushLink = want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK] as string
return {
isPush: true, online: false, pushLink: pushLink, want: want
}
}
}
return {
isPush: false, online: false
}
}
static jumpWithPushLink(pushLink: string) {
AppInnerLink.jumpWithLink(pushLink)
}
}
\ No newline at end of file
... ...
... ... @@ -7,7 +7,6 @@ import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import { DeviceUtil, EmitterEventId, EmitterUtils, WindowModel } from 'wdKit';
import { ConfigurationConstant } from '@kit.AbilityKit';
import { WDPushNotificationManager } from 'wdHwAbility/Index';
import { StartupManager } from '../startupmanager/StartupManager';
let floatWindowClass: window.Window | null = null;
... ... @@ -28,7 +27,7 @@ export default class EntryAbility extends UIAbility {
// App活着情况下,点击推送通知进入
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
WDPushNotificationManager.getInstance().onWant(want)
StartupManager.sharedInstance().appOnNewWant(want, launchParam)
}
onDestroy(): void {
... ...
import { BottomNavigationComponent, LogoutViewModel, PermissionDesComponent } from 'wdComponent';
import { BreakpointConstants } from 'wdConstant';
import { HWLocationUtils, WDPushNotificationManager } from 'wdHwAbility/Index';
import { common } from '@kit.AbilityKit';
import { BreakpointSystem, EmitterEventId, EmitterUtils, Logger, MpaasUpgradeCheck, WindowModel } from 'wdKit';
import { promptAction, window } from '@kit.ArkUI';
... ... @@ -33,16 +32,6 @@ struct MainPage {
this.breakpointSystem.register()
let context = getContext(this) as common.UIAbilityContext
WDPushNotificationManager.getInstance().requestEnableNotifications(context).then((enabled) => {
if (enabled) {
WDPushNotificationManager.getInstance().fetchTokenAndBindProfileId()
// WDPushNotificationManager.getInstance().sendLocalNotification()
}
HWLocationUtils.startLocationService()
})
Logger.info(TAG, `aboutToAppear `);
EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, () => {
LogoutViewModel.clearLoginInfo()
... ...
import { AbilityConstant, common, Want } from '@kit.AbilityKit'
import { WDPushNotificationManager } from 'wdHwAbility/Index'
import { DeviceUtil,
EmitterEventId,
EmitterUtils,
... ... @@ -17,6 +16,7 @@ import { registerRouter } from 'wdRouter/Index'
import { TrackingModule } from 'wdTracking/Index'
import { JSON } from '@kit.ArkTS'
import app from '@system.app'
import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index'
const TAG = "[StartupManager]"
... ... @@ -25,6 +25,8 @@ export class StartupManager {
private context?: common.UIAbilityContext
private constructor() {
}
private static _manger?: StartupManager
static sharedInstance(): StartupManager {
if (!StartupManager._manger) {
... ... @@ -60,10 +62,14 @@ export class StartupManager {
this.preInitUmentStat()
// 通知栏点击后启动
WDPushNotificationManager.getInstance().onWant(want)
GetuiPush.sharedInstance().onWant(want)
Logger.debug(TAG, "App onCreate: finised")
}
appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) {
GetuiPush.sharedInstance().onNewWant(want)
}
appOnDestory() {
Logger.debug(TAG, "App onDestory")
NetworkManager.getInstance().release()
... ... @@ -91,13 +97,19 @@ export class StartupManager {
Logger.debug(TAG, "App 必要初始化完成")
}
// 到达主页后,初始化非必须部分
// 初次到达主页后,初始化非必须部分
appReachMainPage() : Promise<void> {
return new Promise((resolve) => {
Logger.debug(TAG, "App 进入首页,开始其他任务初始化")
Logger.debug(TAG, "App 初次进入首页,开始其他任务初始化")
LoginModule.reportDeviceInfo()
GetuiPush.sharedInstance().requestEnableNotifications(this.context!).then((enabled) => {
HWLocationUtils.startLocationService()
})
GetuiPush.sharedInstance().onReachMainPage()
//TODO:
resolve()
... ... @@ -130,7 +142,8 @@ export class StartupManager {
}
private initGeTuiPush() {
// Logger.debug(TAG, "App 初始化")
Logger.debug(TAG, "App 个推推送 初始化")
GetuiPush.sharedInstance().init(this.context!)
}
private initLocation() {
... ... @@ -170,4 +183,4 @@ export class StartupManager {
private initOthers() {
}
}
\ No newline at end of file
}
... ...
... ... @@ -14,7 +14,7 @@
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"name": "EntryAbility", // 这里不能改动,和后台推送有绑定
"srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc",
"icon": "$media:app_icon",
... ... @@ -28,8 +28,15 @@
"entity.system.home"
],
"actions": [
"action.system.home"
]
"action.system.home",
"com.test.pushaction"
],
"uris" : [{
"scheme": 'rmrbapp',
"host": 'rmrb.app',
'port': '8080',
"path": 'openwith'
}]
}
]
}
... ...