类型NSnull的JSON值无法转换为NSString
问题描述:
我的反应原生Firebase APL有一个奇怪的错误。类型NSnull的JSON值无法转换为NSString
react-native run-android工作正常,没有错误。
但react-native run-ios失败,并且类型为NSnull的JSON值无法转换为NSString。
源代码如下(主注册类认证工作的火力)
我觉得火力地堡类对iOS和Android不同的ACT转换JSON为文本。
任何建议赞赏。
商事
主要
//这里初始化火力应用程序,并根据需要将其传递到其他组件。只在启动时初始化。
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
答
我深深地调试了这个BUG。 最后我发现它如下。
<Image
source={{uri: 'this.state.user.photoURL'}} <<<single quotation was added.
style={styles.image}
/>
我没有想到会有这样的错误。
Thanks Shoji
+0
为什么ios和Android会在没有单引号的情况下执行不同的操作? – itagaki
该错误似乎很具体。这个问题应该尝试去做同样的事情。 – user2864740
CLASS firebase叫我的APL如下。 const firebaseApp = firebase.initializeApp(firebaseConfig); 常量退订= firebaseApp.auth()。onAuthStateChanged((用户)=> { this.props.firebaseApp.auth()。createUserWithEmailAndPassword( 常量的UserData = this.props.firebaseApp.auth()。 currentUser; 源= {{URI:this.state.user.photoURL}} /> //注销,一旦完成后,用户返回到登录屏幕 this.props.firebaseApp。 auth()。signOut()。then(()=> { – itagaki