ReactNative
苹果账号第三方登录,下面我们将对于在RN
中配置使用Apple
登录的配置和使用说明。
原文地址
安装
- 安装三方模块
npm i @invertase/react-native-apple-authentication
- 在
Xcode
中添加Sign Apple
如下图所示
使用
在业务逻辑中我们自定义登录模块
// apple 账号登录
const handleAppleLogin = async () => {
try {
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: appleAuth.Operation.LOGIN,
requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME]
})
if (!appleAuthRequestResponse.identityToken) {
throw 'Apple Sign-In failed - no identify token returned'
}
const { identityToken, nonce, email, user, fullName } = appleAuthRequestResponse
// const credentialState = await appleAuth.getCredentialStateForUser(appleAuthRequestResponse.user)
// 001224.63aea5c8ff124f63b83741ae928b2c9f.0007
console.log('appleAuthRequestResponse', appleAuthRequestResponse)
Alert.alert(nonce, JSON.stringify(identityToken))
} catch (err) {}
}