基本背景
鸿蒙元服务不需要自己处理隐私弹窗,鸿蒙强制要求结束隐私协议托管,关联 client_id 之后会自动弹窗隐私协议,下面内容主要针对鸿蒙应用开发用户。
鸿蒙应用上架需要配置隐私协议、用户协议。这部分内容可参考 鸿蒙如何设置隐私协议弹窗
这里做技术实现说明。
内容已迁移到 鸿蒙如何设置隐私协议弹窗
补充:编写 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'
2 个评论
要回复文章请先登录或注册
DCloud_UNI_OttoJi (作者)
2***@qq.com