代码如下:
async goApply() {
const res = await uni.getSetting({ withSubscriptions: true })
const go = () => {
this.sureApply() //接口
}
let s;
try {
const [, { subscriptionsSetting: { itemSettings: _s } }] = await uni.getSetting({ withSubscriptions: true })
s = _s
} catch(e) {
go()
return false
}
const tmplIds = [
't9_3hsUqanNeYNheYEDtsL26VWqCVRrFBaj7QLiSh2M',
'8R9SbxBeziYURpzOqMYQUyd1dCzBKQVuayrpeUr4PSQ',
'FjXnhSWmUSoCLf-eC1zkNxbojpD7bzoe0U9yVGRZR54'
]
const t_alen = tmplIds.length
let t_len = 0
if(s) {
const s_k = Object.keys(s)
const s_v = Object.values(s)
t_len = tmplIds.filter(id => s_k.indexOf(id) !== -1).length
}
if(!s || t_len !== t_alen) {
uni.requestSubscribeMessage({
tmplIds,
success(res) {
const _o = Object.assign({}, res)
Reflect.deleteProperty(_o, 'errMsg')
const a_len = Object.values(_o).filter(s => s === 'accept').length
if(a_len !== t_alen){
uni.showModal({
title: '提示',
content: '请选择订阅服务,以便我们通知您活动信息',
showCancel: false
})
} else {
go()
}
},
fail(err) {
uni.showModal({
title: '失败',
content: '打开订阅服务失败',
showCancel: false
})
go()
}
})
} else {
go()
}
},
网友评论