要解决“本地可正常工作的AppleSignIn (with Firebase & Expo),但是独立运行时无法工作”的问题,可以尝试以下解决方法:
确保正确配置 Firebase:
FirebaseApp.configure() 方法手动配置 Firebase。检查 Expo SDK 版本:
检查 Xcode 配置:
检查权限设置:
检查错误日志:
以下是一个示例,展示了如何在独立运行时配置和使用 AppleSignIn:
import * as AppleAuthentication from 'expo-apple-authentication';
import * as firebase from 'firebase';
// 初始化 Firebase
firebase.initializeApp(firebaseConfig);
// 配置 AppleSignIn
async function configureAppleSignIn() {
if (Platform.OS === 'ios') {
try {
// 请求 AppleSignIn 权限
await AppleAuthentication.requestAsync({
requestedScopes: [AppleAuthentication.AppleAuthenticationScope.FULL_NAME, AppleAuthentication.AppleAuthenticationScope.EMAIL],
});
// 获取 AppleSignIn 凭据
const credential = await AppleAuthentication.signInAsync();
// 使用凭据登录 Firebase
const { id_token, nonce } = credential;
const appleCredential = firebase.auth.AppleAuthProvider.credential(id_token, nonce);
await firebase.auth().signInWithCredential(appleCredential);
// 登录成功后的处理
// ...
} catch (error) {
console.log('AppleSignIn 错误:', error);
}
}
}
// 在组件挂载时调用配置函数
useEffect(() => {
configureAppleSignIn();
}, []);
请注意,上述示例只是一个简单的示范,实际配置和使用 AppleSignIn 可能会因项目的不同而有所差异。根据您的具体需求和项目设置,您可能需要进一步调整代码。