ReactNative 使用 Apple 登录

本文最后更新于 2024年5月16日 上午

ReactNative 苹果账号第三方登录,下面我们将对于在RN中配置使用Apple登录的配置和使用说明。

安装

  • 安装三方模块
1
npm i @invertase/react-native-apple-authentication 
  • Xcode中添加Sign Apple如下图所示

使用

在业务逻辑中我们自定义登录模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 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) {}
}


ReactNative 使用 Apple 登录
https://dev.dgdream.online/2024/05/08/reactnative使用apple登录/
作者
执念
发布于
2024年5月8日
更新于
2024年5月16日
许可协议