React native React Native:Android上独立的Expo内置应用程序在使用Facebook登录时崩溃(适用于iOS)
我有一个使用Expo管理工作流构建的React原生应用程序。我正在为我的应用程序使用Facebook登录和Firebase身份验证。我的理解是,在Expo应用程序中运行时无法对其进行测试,只能在独立应用程序中使用 FB登录在我的React native React Native:Android上独立的Expo内置应用程序在使用Facebook登录时崩溃(适用于iOS),react-native,expo,facebook-login,React Native,Expo,Facebook Login,我有一个使用Expo管理工作流构建的React原生应用程序。我正在为我的应用程序使用Facebook登录和Firebase身份验证。我的理解是,在Expo应用程序中运行时无法对其进行测试,只能在独立应用程序中使用 FB登录在我的iOS独立应用程序中运行良好,但在android中,它甚至在Facebook登录屏幕出现之前就崩溃了。我的LandingPage加载,但只要我按下“使用Facebook登录”按钮,它就会崩溃 下面是我的app.json文件和我的登录代码。根据说明,我还将Facebook密
iOS
独立应用程序中运行良好,但在android
中,它甚至在Facebook登录屏幕出现之前就崩溃了。我的LandingPage
加载,但只要我按下“使用Facebook登录”按钮,它就会崩溃
下面是我的app.json
文件和我的登录代码。根据说明,我还将Facebook密钥散列添加到我在Facebook开发者网站上的项目中。有谁能帮我理解出了什么问题吗
app.json:
{
"expo": {
"name": "Pick Up",
"slug": "PickUp",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/ball-and-glove-5.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"notification": {
"icon": "./assets/ball-and-glove-5.png",
"color": "#fff",
"androidMode": "default"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"userInterfaceStyle": "light",
"config": {
"googleMobileAdsAppId": "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx",
"googleMapsApiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"bundleIdentifier": "com.myapp.name",
"buildNumber": "1.0.0"
},
"userInterfaceStyle": "automatic",
"android": {
"useNextNotificationsApi": true,
"userInterfaceStyle": "dark",
"config": {
"googleMobileAdsAppId": "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx",
"googleMaps": {
"apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
},
"package": "com.myapp.name",
"versionCode": 1
},
"web": {
"favicon": "./assets/favicon.png"
},
"facebookScheme": "fbxxxxxxxxxxxxxxxx",
"facebookAppId": "xxxxxxxxxxxxxxx",
"facebookDisplayName": "myname"
}
}
登录代码:
import React, { useState, useEffect, useContext } from 'react';
import { Alert, Animated, Image, StatusBar, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import * as WebBrowser from 'expo-web-browser';
import * as Facebook from 'expo-facebook';
import * as firebase from 'firebase';
import { loginUser } from '../../firebase.js';
import { StoreContext } from '../../contexts/storeContext';
const turquoise = "#4ECDC4";
const LandingPage = ({ navigation }) => {
const store = useContext(StoreContext);
const handleFacebook = async () => {
try {
await Facebook.initializeAsync();
const options = {
permissions: ["public_profile"]
}
const { type, token } = await Facebook.logInWithReadPermissionsAsync(options);
if (type === "success") {
const credential = firebase.auth.FacebookAuthProvider.credential(token);
if (credential) {
const bool = await loginUser(credential);
}
}
else {
Alert.alert("", "There was a problem. Please try again.");
}
}
catch (e) {
console.log("e : ", e);
Alert.alert("", e);
}
}
return (
<View>
<StatusBar barStyle="dark-content" backgroundColor={ turquoise } />
<View>
<TouchableOpacity onPress={ handleFacebook }>
<Ionicons name="logo-facebook" />
<Text>Continue with Facebookk</Text>
</TouchableOpacity>
<TouchableOpacity onPress={ () => navigation.navigate("PhoneVerification") }>
<Text>Use cell phone number</Text>
</TouchableOpacity>
</View>
<View>
<Image
resizeMode="contain"
source={require('../../assets/new-logo.png')}
/>
</View>
</View>
)
}
从“React”导入React,{useState,useEffect,useContext};
从“react native”导入{警报、动画、图像、状态栏、样式表、文本、TouchableOpacity、视图};
从“@expo/vector icons”导入{Ionicons};
从“世博网络浏览器”导入*作为网络浏览器;
从“expo Facebook”导入*作为Facebook;
从“firebase”导入*作为firebase;
从'../../firebase.js'导入{loginUser};
从“../../contents/StoreContext”导入{StoreContext};
常量绿松石=“#4ECDC4”;
常量登录页=({navigation})=>{
const store=useContext(StoreContext);
const handleFacebook=async()=>{
试一试{
等待Facebook.initializeAsync();
常量选项={
权限:[“公共_配置文件”]
}
const{type,token}=wait Facebook.logInWithReadPermissionsAsync(选项);
如果(类型==“成功”){
const credential=firebase.auth.FacebookAuthProvider.credential(令牌);
if(凭证){
const bool=等待登录用户(凭证);
}
}
否则{
警报。警报(“,”出现问题。请重试。“);
}
}
捕获(e){
console.log(“e:”,e);
警惕。警惕(“,e);
}
}
返回(
继续使用Facebookk
导航。导航(“电话验证”)}>
使用手机号码
)
}
问题是,对于Android,Facebook.initializeAsync()
需要传递一个参数——您的FB appID
const handleFacebook = async () => {
try {
await Facebook.initializeAsync("123456789"); // <-- your FB appID
const options = {
permissions: ["public_profile"]
}
const { type, token } = await Facebook.logInWithReadPermissionsAsync(options);
if (type === "success") {
const credential = firebase.auth.FacebookAuthProvider.credential(token);
// do the rest of your Firebase login logic
}
else {
Alert.alert("", "There was a problem. Please try again.");
}
}
catch (e) {
console.log("e : ", e);
Alert.alert("", e);
}
}
const handleFacebook=async()=>{
试一试{
等待Facebook.initializeAsync(“123456789”)//