这个需求是必须的吧?
UI可以忽略了 后面根据 设计师的页面自己修改
点击同意后可以进入到首页面
再次打开应用后 不显示隐私协议页面
也可以添加一个 广告页面这个随你自己
答题实现的思路是这样的
这个目前全网应该很少吧
放出主要的源码
import router from '@ohos.router'
import preferences from '@ohos.data.preferences';
import CustomDialogPrivateComponent from '../Component/CustomDialogPrivateComponent';
import common from '@ohos.app.ability.common';
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
private context?: common.UIAbilityContext;
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogPrivateComponent(
{
cancel: () => {
this.onCancel();
},
confirm: () => {
this.onConfirm();
}
}),
alignment: DialogAlignment.Center,
offset: { dx: 0, dy: 10 },
customStyle: true,
autoCancel: false
});
onCancel(){
this.context?.terminateSelf()
}
onConfirm(){
let self = this
this.getDataPreferences(this).then((preferences: preferences.Preferences) => {
preferences.put('isPrivate',false,function(err,val){
if (err) {
console.log('存储错误',err)
return
}
preferences.flush()
self.dialogController.close()
self.jumpToHomePage()
})
})
}
jumpToHomePage(){
router.replaceUrl({url:'pages/MainPage'})
}
getDataPreferences(common: Object) {
return preferences.getPreferences(getContext(common), 'myStore');
}
onPageShow(){
this.getDataPreferences(this).then((preferences: preferences.Preferences) => {
preferences.get('isPrivate', true).then((value: preferences.ValueType) => {
console.info('LauncherPage', 'onPageShow value: ' + value);
if (value) {
this.dialogController.open();
}
else {
this.jumpToHomePage();
}
});
});
}
aboutToAppear(){
// this.getDataPreferences(this).then((preferences)=>{
// preferences.delete('isPrivate')
// })
// setTimeout(()=>{
// router.replaceUrl({url:'pages/MainPage'})
// },2000)
}
build() {
Column() {
Image($r('app.media.landing_image'))
.height('100%')
.width('100%')
.objectFit(ImageFit.ScaleDown)
}
.width('100%')
.height('100%')
}
}