【发布时间】:2026-01-10 20:30:01
【问题描述】:
我的 react-native Firebase APL 有一个奇怪的错误。
react-native run-android 工作正常,没有错误。
但是 react-native run-ios 失败,NSnull 类型的 JSON 值无法转换为 NSString。
源代码如下。(主要和注册类在firebase上进行身份验证工作)
我认为 Firebase Class 在 ios 和 Android 上有不同的 ACT 来将 JSON 转换为文本。
任何建议表示赞赏。
商事
主要
// 在此处初始化firebase应用并根据需要将其传递给其他组件。仅在启动时初始化。
const firebaseApp = firebase.initializeApp(firebaseConfig);
var GiftedMessenger = require('react-native-gifted-messenger');
let styles = {}
class Pricing extends Component {
constructor(props){
super(props);
this.state = {
page: null
};
/* this.itemsRef = this.getRef().child('items'); */
}
componentWillMount(){
// We must asynchronously get the auth state, if we use currentUser here, it'll be null
const unsubscribe = firebaseApp.auth().onAuthStateChanged((user) => {
// If the user is logged in take them to the accounts screen
if (user != null) {
this.setState({page: Account});
console.log('(user != null)')
return;
}
// otherwise have them login
console.log('(user != Login)')
this.setState({page: Login});
// unsubscribe this observer
unsubscribe();
});
}
render() {
if (this.state.page) {
return (
// Take the user to whatever page we set the state to.
// We will use a transition where the new page will slide in from the right.
<Navigator
initialRoute={{component: this.state.page}}
configureScene={() => {
return Navigator.SceneConfigs.FloatFromRight;
}}
renderScene={(route, navigator) => {
if(route.component){
// Pass the navigator the the page so it can navigate as well.
// Pass firebaseApp so it can make calls to firebase.
return React.createElement(route.component, { navigator, firebaseApp});
}
}} />
);
} else {
return (
// Our default loading view while waiting to hear back from firebase
【问题讨论】:
-
这个错误似乎很具体。问题应该尝试做同样的事情。
-
CLASS firebase 调用我的 APL 如下。常量 firebaseApp = firebase.initializeApp(firebaseConfig); const unsubscribe = firebaseApp.auth().onAuthStateChanged((user) => { this.props.firebaseApp.auth().createUserWithEmailAndPassword( const userData = this.props.firebaseApp.auth().currentUser; source={{uri: this.state.user.photoURL}} /> // 注销,一旦完成,将用户返回到登录屏幕 this.props.firebaseApp.auth().signOut().then(() => {
标签: android ios json firebase react-native