使用了uni-im后,说明文档中关于“基于老版uni-id(版本号:3.x) 开发的项目,需要如下改造:
在登录成功和token续期后,绑定当前账号与设备推送标识的关联关系。示例代码:”
我想问一下,*这段代码是需要在哪个文件里添加呢*****?
const uniIdCo = uniCloud.importObject("uni-id-co", {customUI: true})
uni.getPushClientId({
success: async function(e) {
console.log(e)
let pushClientId = e.cid
let res = await uniIdCo.setPushCid({
pushClientId
})
console.log('getPushClientId', res);
},
fail(e) {
console.error(e)
}
})
w***@163.com
- 发布:2023-05-30 09:58
- 更新:2024-12-20 08:57
- 阅读:442
2 个回复
6***@qq.com
放在登录之后
6***@qq.com
this.$H.post("user/app/smsLogin", this.form).then(res => {
console.log("user/app/smsLogin",res)
if (res.code == 0) {
let token = res.token
let uniIdToken = res.uniIdToken
// 存储你自己项目的token到storage(仅供参考,根据你自己的登录逻辑而定)
uni.setStorageSync('token', token)
uni.setStorageSync('userInfo', res.userInfo)
// 存储uni-id的token和token过期时间到storage(必须按以下格式存储)
uni.setStorageSync('uni_id_token_expired', uniIdToken.tokenExpired)
uni.setStorageSync('uni_id_token', uniIdToken.token)
// 获取push的ClientId同步到uni-id
uni.getPushClientId({
success: async function(e) {
console.log('async',e)
let pushClientId = e.cid
console.log('pushClientId',pushClientId);