在 iOS13 中,如果 App 提供第三方登錄,就必須添加 蘋果登錄 Sign in with Apple 選項,並要求所有開發者於 2020年4月之前 完成現有應用的更新,否則審核不給通過。
在 HBuilderX 配置 apple 登錄
1、在 HBuilderX 打開需要配置 蘋果授權登錄(Sign in with Apple)的項目找到 manifest.json-App SDK配置-登錄鑒權-蘋果登錄(Sign In with Apple) 將其勾選
代碼
1、在 template 添加以下代碼, 蘋果授權登錄(Sign in with Apple)是 iOS 13 才有的,做下系統版本判斷
1 <template> 2 <view class="content"> 3 <!-- 蘋果登錄 --> 4 <view class="sign-in-with-apple" v-if="system >= 13 && platform=='ios'" @click="appleLogin">sign in with apple</view> 5 </view> 6 </template>
2、在 script 里添加點擊以下代碼
export default { data() { return { title: 'Hello', system: '', // 系統版本 platform: '', // 平台 } }, onLoad() { // 先判斷 系統版本 uni.getSystemInfo({ success: (res) => { this.system = res.system this.platform = res.platform },fail: (err) => { },complete: () => { } }) }, methods: { // 蘋果登錄 appleLogin() { // 判斷是 iOS13版本 uni.login({ provider: 'apple', success: (loginRes) => { uni.getUserInfo({ provider: 'apple', success: (userInfoRes) => { }, fail: (err) => { } }) }, fail: (err) => { } }) } } } </script>
3、授權成功回調
{ "errMsg": "getUserInfo:ok", "rawData": "json字符串", "userInfo": { "openId": "xxx.xxxxx.xxx", // 蘋果用戶唯一標識符,該值在同一個開發者賬號下的所有 App 下是一樣的,開發者可以用該唯一標識符與自己后台系統的賬號體系綁定起來。 "fullName": {}, // 當且僅當第一次授權才會返回 "authorizationCode": "12345678xxx", // 服務器驗證需要使用的參數 "identityToken": "header.payload.signature", // 服務器驗證需要使用的參數 "realUserStatus": 1 // 用於判斷當前登錄的蘋果賬號是否是一個真實用戶 }, "signature": "" }