Ich habe eine Test-App in nativen reagieren, und alles funktioniert gut, wenn ich die Debug js aus der Ferne aktiviert habe. Es funktioniert gut in Gerät (von XCode) und Simulator, nach Durchlauf:React Native Atob()/btoa() funktioniert nicht ohne Remote-JS-Debugging
react-native run ios
Das Problem ist, dass, wenn ich remote js Debuggen beenden, der Login-Test nicht anymore.The Login Logik funktioniert, ist sehr einfach, ich bin Beim Abrufen einer API zum Testen einer Anmeldung ist der API-Endpunkt über https.
Was muss ich ändern?
Aktualisiert: Dieser Code funktioniert perfekt mit JS Debug Remote Enabled, wenn ich es deaktiviere, funktioniert es nicht mehr.
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
View,
Button,
Alert
} from 'react-native'
export default class MyClass extends Component {
constructor (props) {
super(props)
this.testFetch = this.testFetch.bind(this)
}
async testFetch() {
const email = '[email protected]'
const password = '123456'
try {
const response = await fetch('https://www.example.com/api/auth/login', {
/* eslint no-undef: 0 */
method: 'POST',
headers: {
'Accept': 'application/json' /* eslint quote-props: 0 */,
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(email + ':' + password)
}
})
Alert.alert('Error fail!', 'Fail')
console.log(response)
} catch (error) {
Alert.alert('Error response!', 'Ok')
}
}
render() {
return (
<View style={styles.container}>
<Button
onPress={this.testFetch}
title="Test me!"
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5
}
})
AppRegistry.registerComponent('testingReactNative',() => MyClass)
Danke.
Sie benötigen mindestens einen Code hier hinzufügen. Es ist unwahrscheinlich, dass JS remote debugging diesen Fehler verursacht. – zvona
Hi @zvona Ich habe die Frage mit Code aktualisiert ... danke. – chemitaxis
Ok, mein Fehler ist, dass "btoa" nicht definiert ist, wenn es ohne Debug ausgeführt wird ... aber warum? :) – chemitaxis