Tôi có một ứng dụng thử nghiệm trong phản ứng gốc, và tất cả hoạt động tốt khi tôi đã kích hoạt các js gỡ lỗi từ xa. Nó hoạt động tốt trong thiết bị (từ XCode) và mô phỏng, sau khi chạy:React Native atob()/btoa() không hoạt động mà không cần gỡ lỗi JS từ xa
react-native run ios
Vấn đề là nếu tôi dừng lại gỡ lỗi js từ xa, kiểm tra đăng nhập không hoạt động anymore.The lý đăng nhập là rất đơn giản, tôi là tìm nạp api để kiểm tra thông tin đăng nhập, điểm cuối API vượt quá https.
Điều tôi cần thay đổi?
Cập nhật: Mã này hoạt động hoàn hảo với JS Debug Remote Enabled, nếu tôi tắt nó, nó sẽ không hoạt động nữa.
/**
* 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)
Cảm ơn.
Bạn cần ít nhất để thêm một số mã tại đây. Gỡ lỗi từ xa JS không có khả năng gây ra lỗi này. – zvona
Xin chào @zvona Tôi đã cập nhật câu hỏi với mã ... cảm ơn. – chemitaxis
Ok, lỗi của tôi là "btoa" là không xác định khi thực thi nó mà không cần gỡ lỗi ... nhưng tại sao? :) – chemitaxis