Uniapp Login sign in Apple
Prerequisite: If the third-party login has been implemented in the software, it must also have the function of Sign in Apple, otherwise the audit will not pass
Preparation: UniApp’s built-in sign in Apple must be packaged with a custom dock (i.e., cloud packaged)
Construction:
-
Find the manifest. Json configuration file for your project, then go to [App module configuration]-[OAuth(Login authorization)]-[Apple Login] and install the Sign in Apple module
-
Cloud packaging, find the top toolbar [issue]-[Cloud packaging], need to provide the corresponding certificate; Note: The UDID of IOS corresponding to the tested mobile phone must be added to the corresponding certificate; otherwise, an error message “Failed to install return code=-402620395” will be displayed later. UDID can be obtained from this website, very convenient, www.pgyer.com/tools/udid;
-
Function implementation
-
IOS13 + supports apple login. Therefore, determine the device type and OS version
uni.getSystemInfo({ success:(res) = > { // console.log(" mobile system info ",res) this.system = res.system / / 14.4.1 this.platform = res.platform //ios}})Copy the code
-
To achieve login, send requests to the background; Apple login, the default is not shared email, that is, the default can not get the user’s email; Only the user chooses the shared email, can get the email;
LoginForApple() { let that = this uni.getProvider({ // Get the third-party login type service: 'oauth'.success: function (res) { // console.log(res.provider) // Determine apple login 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' // Check whether the user chooses to share the mailbox let email = "" if(user.email){ email = user.email }else{ email = "" } // console.log(' user's email ',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 login data saved successfully ') that.$emit('closelogin',that.closelogin) }).catch(err= >{ console.log(err) }) } }) }, fail: err= > { console.log('Apple login failed' + JSON.stringify(err)) uni.showToast({ title:'Login failed'.icon:'none'})}})}},fail: err= > { uni.showToast({ title:'Login failed'.icon:'none'}}}})),Copy the code
-
If you have any other questions, please talk to me in privateCopy the code