提交 b72ea928 编写于 作者: DCloud_iOS_WZT's avatar DCloud_iOS_WZT

新增 隐私协议API相关示例

上级 b06eeb85
...@@ -1183,6 +1183,13 @@ ...@@ -1183,6 +1183,13 @@
"navigationBarTitleText": "provider | 服务提供商" "navigationBarTitleText": "provider | 服务提供商"
} }
}, },
{
"path": "pages/API/privacy/privacy",
"group": "1,1,7",
"style": {
"navigationBarTitleText": "privacy | 服务提供商"
}
},
// #endif // #endif
{ {
"path": "pages/API/uni-push/uni-push", "path": "pages/API/uni-push/uni-push",
...@@ -2201,6 +2208,10 @@ ...@@ -2201,6 +2208,10 @@
{ {
"id": "api.base.provider", "id": "api.base.provider",
"name": "provider" "name": "provider"
},
{
"id": "api.base.privacy",
"name": "privacy"
} }
] ]
}, },
......
<template>
<view class="uni-padding-wrap">
<page-head :title="title"></page-head>
<view class="item-box">
<text>当前应用隐私状态:</text>
<text>{{ appPrivacy }}</text>
</view>
<view>
<button class="privacy-button" type="primary" @tap="getPrivacySetting">
获取隐私协议状态
</button>
<button class="privacy-button" type="primary" open-type="agreePrivacyAuthorization">
同意隐私协议
</button>
<button class="privacy-button" type="primary" @tap="resetPrivacyAuthorization">
重置隐私协议状态
</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: '隐私信息授权',
appPrivacy: '未获取',
listenId: 0
}
},
onReady() {
//添加 隐私协议监听
const id = uni.onPrivacyAuthorizationChange((res) => {
this.appPrivacy = res.needAuthorization ? "未同意" : "已同意"
const privacyState = "监听到隐私协议状态已变更为 " + this.appPrivacy;
uni.showToast({
"position": "bottom",
"title": privacyState
})
})
this.listenId = id;
uni.showToast({
"position": "bottom",
"title": "开启监听隐私协议状态"
})
},
onUnload() {
//注销监听
uni.offPrivacyAuthorizationChange(this.listenId)
this.listenId = 0;
uni.showToast({
"position": "bottom",
"title": "已停止监听隐私协议状态"
})
},
methods: {
getPrivacySetting() {
uni.getPrivacySetting({
success: (res) => {
this.appPrivacy = res.needAuthorization ? "未同意" : "已同意"
}
})
},
resetPrivacyAuthorization(){
uni.resetPrivacyAuthorization()
}
}
}
</script>
<style>
.item-box {
margin-bottom: 15px;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.privacy-button{
margin-top: 15px;
margin-bottom: 15px;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册