基本背景
鸿蒙应用上架需要配置隐私协议、用户协议。这部分内容可参考 鸿蒙如何设置隐私协议弹窗
这里做技术实现说明。
方案一:自行绘制
目前已经上架的 hellouniapp应用,和一部分已上架用户案例,都是使用自己弹窗完成的。可使用页面组件弹窗、也可制作单独的页面进行路由跳转,用户的同意状态存储 storage 中,后续启动根据参数来动态判断。
这里相对容易,不做进一步说明。
注意:元服务中只能选择托管协议,鸿蒙应用可在托管协议、自定义填写 URL 二选一,如果选择自定义 URL,只能使用方案一自定绘制。
方案二:官方隐私协议托管
鸿蒙的 AGC 后台有隐私协议托管功能,通过填写标准化的文档,完成隐私协议的填写,按照要求填写内容,生成协议,在上架提审过程中选择即可。具体参鸿蒙文档 隐私管理服务
好处:
- 隐私协议按照要求填写,不会因为格式出错被驳回,正确填写相关 sdk、权限说明即可。
- 网页由鸿蒙托管访问有保障。
- 可使用鸿蒙 api 唤起系统弹窗,视觉风格和鸿蒙统一。
整体步骤如下
1 后台填写隐私协议
得到 url 地址
2. 添加 debug 代码
代码中,编辑 harmony-configs/entry/src/main/module.json5 按照文档要求,添加三个字段,分别是
- appgallery_privacy_hosted
- appgallery_privacy_link_privacy_statement
- appgallery_privacy_link_user_agreement
填写这个三个弹窗的作用是模拟线上正式环境,用于测试通过 api 唤起弹窗的效果,务必注意,并不是为了实现自动弹窗
3. 编写 uts 插件
编写 uts 插件,完成弹窗,这里提供代码片段,后续提供 uts 插件市场链接。
新建 uts 插件,比如 hamrony-privacy-dialog ,编辑 uni_modules/harmony-privacy-dialog/utssdk/app-harmony/index.uts
填写下面代码,这段代码导出了三个方法,和官方的 ets 代码完全一致,检查隐私协议信息、获取签署状态、主动唤起隐私弹窗。页面中引入代码调用即可。
import { privacyManager } from '@kit.AppGalleryKit';
// import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
export const getInfo = () => {
let err = ''
try {
let appPrivacyManageInfo : privacyManager.AppPrivacyMgmtInfo = privacyManager.getAppPrivacyMgmtInfo();
console.info(0, 'TAG', "Succeeded in getting AppPrivacyManageInfo type: " + appPrivacyManageInfo["type"]);
let privacyLinkInfoArray : privacyManager.AppPrivacyLink[] = appPrivacyManageInfo.privacyInfo;
console.info(0, 'TAG', "Succeeded in getting AppPrivacyManageInfo size = " + privacyLinkInfoArray.length);
for (let i = 0; i < privacyLinkInfoArray.length; i++) {
console.info(0, 'TAG', "Succeeded in getting AppPrivacyManageInfo type = " + privacyLinkInfoArray[i]["type"] + ", version = " + privacyLinkInfoArray[i]["versionCode"] + ", url = " + privacyLinkInfoArray[i]["url"]);
}
} catch (error) {
err = error.message
console.error(0, 'TAG', "GetAppPrivacyManageInfoPublic exception code: " + error.code + ", exception message: " + error.message);
}
return err
}
export const getStatus = () => {
try {
let appPrivacyResults : privacyManager.AppPrivacyResult[] = privacyManager.getAppPrivacyResult();
console.info(0, 'TAG', "Succeeded in getting AppPrivacyResult size = " + appPrivacyResults.length);
for (let i = 0; i < appPrivacyResults.length; i++) {
console.info(0, 'TAG', "Succeeded in getting AppPrivacyResult type = " + appPrivacyResults[i]["type"] + ", version = " + appPrivacyResults[i]["versionCode"] + ", result = " + appPrivacyResults[i]["result"]);
}
} catch (error) {
console.error(0, 'TAG', "GetAppPrivacyResultPublic exception code: " + error.code + ", exception message: " + error.message);
}
}
export const requestPrivacy = () => {
try {
const uiContext = UTSHarmony.getUIAbilityContext()
// const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
privacyManager.requestAppPrivacyConsent(uiContext).then((consentResult : privacyManager.ConsentResult) => {
let appPrivacyResults : privacyManager.AppPrivacyResult[] = consentResult["results"];
for (let i = 0; i < appPrivacyResults.length; i++) {
console.info(0, 'TAG', "GetAppPrivacyResult type = " + appPrivacyResults[i]["type"] + ", version = " + appPrivacyResults[i]["versionCode"] + ", result = " + appPrivacyResults[i]["result"] + ", signingTimeStamp = " + appPrivacyResults[i]["signingTimeStamp"]);
}
}).catch((error : BusinessError<Object>) => {
console.error(0, 'TAG', `requestAppPrivacyConsent failed, Code: ${error.code}, message: ${error.message}`);
});
} catch (error) {
console.error(0, 'TAG', "requestAppPrivacyConsent exception code: " + error.code + ", exception message: " + error.message);
}
}
4 页面中引入
import {
getInfo,
getStatus,requestPrivacy
} from '@/uni_modules/harmony-privacy-dialog'
0 个评论
要回复文章请先登录或注册