Uniapp苹果登录sign in Apple

雨点打透心脏的1/2处 2023-01-17 12:58 270阅读 0赞
Uniapp苹果登录sign in Apple
前提:软件内,如果已经实现第三方登录,必须也有sign in Apple功能,否则审核会不通过
准备工作:uniapp自带sign in Apple必须使用自定义基座打包(也就是说可以使用云打包)
开工:
  1. 找到项目的配置文件manifest.json,依次找到 [App模块配置]-[OAuth(登录授权)]-[苹果登录],安装sign in Apple模块
  2. 云打包,找到顶部工具栏[发行]-[云打包],需要提供对应的证书;注意:必须把测试的手机对应的IOS的UDID添加到对应证书,否则后续会报错 “安装失败 return code=-402620395”;获取UDID可通过这个网站获取,很方便,https://www.pgyer.com/tools/udid;
  3. 功能实现

    1. iOS13+ 系统才支持苹果登录,因此需要判断用户设备类型和系统版本

      1. uni.getSystemInfo({
      2. success:(res) => {
      3. // console.log("手机系统信息",res)
      4. this.system = res.system // 14.4.1
      5. this.platform = res.platform //ios
      6. }
      7. })
    2. 实现登录,向后台发送请求;苹果登录,默认是不共享电子邮箱,也就是默认获取不到用户的电子邮箱;只有用户选择了共享电子邮箱,才获取得到电子邮箱;

      1. LoginForApple() {
      2. let that = this
      3. uni.getProvider({
      4. //获取第三方登录类型
      5. service: 'oauth',
      6. success: function (res) {
      7. // console.log(res.provider)
      8. //判断为苹果登录
      9. if(~res.provider.indexOf('apple')) {
      10. uni.login({
      11. provider: 'apple',
      12. success: loginRes => {
      13. uni.getUserInfo({
      14. provider: 'apple',
      15. success: userInfoRes => {
      16. // console.log('user.userInfo',userInfoRes)
      17. let user = userInfoRes.userInfo
      18. let heading = 'http://cdn.kadiantexiao.com/e3729201908141701291608.jpg'
      19. // 判断用户是不是选择共享邮箱
      20. let email = ""
      21. if(user.email){
      22. email = user.email
      23. }else{
      24. email = ""
      25. }
      26. // console.log('用户邮箱',email)
      27. let data = { type:'5',openid:user.openId,heading:heading,nick:'Lonely',email:email}
      28. applelogin(data).then(res=>{
      29. console.log(res.data)
      30. that.saveData(res.data)
      31. // console.log('apple登录数据存成功')
      32. that.$emit('closelogin',that.closelogin)
      33. }).catch(err=>{
      34. console.log(err)
      35. })
      36. }
      37. })
      38. },
      39. fail: err => {
      40. console.log('apple登录失败' + JSON.stringify(err))
      41. uni.showToast({
      42. title:'登录失败',
      43. icon:'none'
      44. })
      45. }
      46. })
      47. }
      48. },
      49. fail: err => {
      50. uni.showToast({
      51. title:'登录失败',
      52. icon:'none'
      53. })
      54. }
      55. })
      56. },

如有其他问题,请私聊我好了

发表评论

表情:
评论列表 (有 0 条评论,270人围观)

还没有评论,来说两句吧...

相关阅读