Uniapp苹果登录sign in Apple
Uniapp苹果登录sign in Apple
前提:软件内,如果已经实现第三方登录,必须也有sign in Apple功能,否则审核会不通过
准备工作:uniapp自带sign in Apple必须使用自定义基座打包(也就是说可以使用云打包)
开工:
- 找到项目的配置文件manifest.json,依次找到 [App模块配置]-[OAuth(登录授权)]-[苹果登录],安装sign in Apple模块
- 云打包,找到顶部工具栏[发行]-[云打包],需要提供对应的证书;注意:必须把测试的手机对应的IOS的UDID添加到对应证书,否则后续会报错 “安装失败 return code=-402620395”;获取UDID可通过这个网站获取,很方便,https://www.pgyer.com/tools/udid;
功能实现
iOS13+ 系统才支持苹果登录,因此需要判断用户设备类型和系统版本
uni.getSystemInfo({
success:(res) => {
// console.log("手机系统信息",res)
this.system = res.system // 14.4.1
this.platform = res.platform //ios
}
})
实现登录,向后台发送请求;苹果登录,默认是不共享电子邮箱,也就是默认获取不到用户的电子邮箱;只有用户选择了共享电子邮箱,才获取得到电子邮箱;
LoginForApple() {
let that = this
uni.getProvider({
//获取第三方登录类型
service: 'oauth',
success: function (res) {
// console.log(res.provider)
//判断为苹果登录
if(~res.provider.indexOf('apple')) {
uni.login({
provider: 'apple',
success: loginRes => {
uni.getUserInfo({
provider: 'apple',
success: userInfoRes => {
// console.log('user.userInfo',userInfoRes)
let user = userInfoRes.userInfo
let heading = 'http://cdn.kadiantexiao.com/e3729201908141701291608.jpg'
// 判断用户是不是选择共享邮箱
let email = ""
if(user.email){
email = user.email
}else{
email = ""
}
// console.log('用户邮箱',email)
let data = { type:'5',openid:user.openId,heading:heading,nick:'Lonely',email:email}
applelogin(data).then(res=>{
console.log(res.data)
that.saveData(res.data)
// console.log('apple登录数据存成功')
that.$emit('closelogin',that.closelogin)
}).catch(err=>{
console.log(err)
})
}
})
},
fail: err => {
console.log('apple登录失败' + JSON.stringify(err))
uni.showToast({
title:'登录失败',
icon:'none'
})
}
})
}
},
fail: err => {
uni.showToast({
title:'登录失败',
icon:'none'
})
}
})
},
如有其他问题,请私聊我好了
还没有评论,来说两句吧...