Uniapp苹果登录
生活随笔
收集整理的這篇文章主要介紹了
Uniapp苹果登录
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.勾選
2.ios打包的證書文件要包含蘋果登錄Sign in with Apple
3.點(diǎn)擊喚起apple登錄
方法一
// 蘋果登錄 getApple() { //方法1uni.login({provider: 'apple',success: (loginRes) => {uni.getUserInfo({provider: 'apple',success: (res) => {//授權(quán)成功let data = {openId:res.userInfo.openId,fullName:res.userInfo.fullName,authorizationCode:res.userInfo.authorizationCode,identityToken:res.userInfo.identityToken,realUserStatus:res.userInfo.realUserStatus,}this.getHttp(data)}})},fail: (err) => {console.log(err)uni.showModal({title: `登錄失敗${err}`})}}); },方法一的打印:只有打包才可以吊起apple登錄,所以登錄成功的邏輯需要先寫好,打印出來的是這樣的
方法二
//方法二 var appleOauth = null;plus.oauth.getServices(function(services) {for (var i in services) {var service = services[i];// 獲取蘋果授權(quán)登錄對象,蘋果授權(quán)登錄id 為 'apple' iOS13以下系統(tǒng),不會(huì)返回蘋果登錄對應(yīng)的 service if (service.id == 'apple') {appleOauth = service;break;}}appleOauth.login(function(oauth) {// 授權(quán)成功,蘋果授權(quán)返回的信息在 oauth.target.appleInfo 中 let data = {login_type: that.login_type,fromUniApp: 1,openId: oauth.target.appleInfo.user,state: oauth.target.appleInfo.state,email: oauth.target.appleInfo.email,fullName: oauth.target.appleInfo.fullName,authorizationCode: oauth.target.appleInfo.authorizationCode,identityToken: oauth.target.appleInfo.identityToken,realUserStatus: oauth.target.appleInfo.realUserStatus,scope: oauth.target.appleInfo.scope,}uni.setStorageSync('appleAuse', 1)uni.setStorageSync('fullName', oauth.target.appleInfo.fullName)uni.setStorageSync('email', oauth.target.appleInfo.email)that.getHttp(data)}, function(err) {// 授權(quán)失敗 error }, {// 默認(rèn)只會(huì)請求用戶名字信息,如需請求用戶郵箱信息,需要設(shè)置 scope: 'email' scope: 'email'})}, function(err) {// 獲取 services 失敗 })方法二的打印,請查看官方文檔
總結(jié)
以上是生活随笔為你收集整理的Uniapp苹果登录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 合肥ibm服务器维修,合肥IBM/thi
- 下一篇: 小屁孩看城管