私はリモートでデバッグjsを有効にしたときに、ネイティブの反応のテストアプリケーションを持っていて、すべて正常に動作します。これは、実行後に、(XCodeのからの)デバイスとシミュレータで正常に動作します:Reactネイティブのatob()/ btoa()がリモートJSデバッグなしで動作しない
react-native run ios
問題は、私は、リモートのJSデバッグを停止した場合、ログインテストはありません、私は非常にシンプルださanymore.Theログインロジックを動作することですAPIをフェッチしてログインをテストすると、APIエンドポイントはhttpsを超えています。
変更する必要がありますか?
更新:このコードは、JS Debug Remote Enabledで完全に動作します。無効にすると、これは動作しなくなります。
/**
* 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)
ありがとうございます。
ここにコードを追加する必要があります。 JSリモートデバッグはこのエラーを引き起こす可能性は低いです。 – zvona
こんにちは@zvona私はコードで質問を更新しました...ありがとうございます。 – chemitaxis
私のエラーは、デバッグせずに実行すると "btoa"が未定義ですが、なぜですか? :) – chemitaxis