Facebook登录
import { AccessToken, LoginManager } from 'react-native-fbsdk-next';
const facebookLogin = ()=>{
LoginManager.logInWithPermissions(['public_profile', 'email', 'user_birthday', 'user_gender'])
.then(
async (result) => {
if (result.isCancelled) {
}else{
const at = await AccessToken.getCurrentAccessToken();
}
}
)
}
Google登录
import { GoogleSignin, GoogleSigninButton, statusCodes } from '@react-native-google-signin/google-signin';
const googleLogin = async()=>{
try{
if (GoogleSignin.isSignedIn()) {
GoogleSignin.signOut();
}
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
const token = await GoogleSignin.getTokens()
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
} else if (error.code === statusCodes.IN_PROGRESS) {
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
} else {
}
}
}
Apple登录
苹果审核时提示使用第三方登录,必须添加苹果登录
需要到Apple开发者控制台找到该应用,勾选复选框Sign in with Apple并单击Edit按钮。选择Enable as a primary App ID并单击Save按钮。 参考开发环境设置
import { appleAuth, AppleButton } from '@invertase/react-native-apple-authentication';
{appleAuth.isSupported && <AppleButton
buttonStyle={AppleButton.Style.BLACK}
buttonType={AppleButton.Type.SIGN_IN}
style={{
width: '60%',
height: 45,
}}
onPress={() => onAppleButtonPress()}
/>}
......
const onAppleButtonPress = async () => {
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: appleAuth.Operation.LOGIN,
requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
});
}
|