javascript - React Native CouchDB/pouchDB 应用程序在发布 apk 中不起作用
问题描述
我正在尝试制作简单的字典项目,我将 CouchDB 用于远程服务器,并将 pouchDB 用于本地。
我使用远程文本文件在本地数据库中预加载数据。
这是我的代码
import React, { Component } from 'react';
...
import { localNoteDb, nameIndex, remote_url, remoteNoteDb } from '../const'
...
let handlerSync = null
class Home extends Component {
constructor(props) {
super(props);
this.state = {
arrNote1: [],
arrNotee: [],
isLoading: false,
text: '',
count: 0,
data1: 0,
data2: 0,
indicator: false,
flagadd: false,
notfoundFlag: false
}
}
....
componentDidMount() {
this.getListNoteFromDb();
}
componentWillUnmount() {
this.getListNoteFromDb();
}
syncDb = () => {
this.setState({ isLoading: true });
//here is my text file to pre load the data from remote amazon s3 text file
localNoteDb.load('https://dictionary.s3.ap-north-14321.amazonaws.com/dumpdb.txt', { proxy: remote_url }).then(() => {
localNoteDb.replicate.from(remote_url).on('complete', function () {
console.log("DONE>>>>>>>")
}).on('error', function (err) {
console.log("ERROR>>>>>" + JSON.stringify(err))
});
var temp = localNoteDb.replicate.from(remote_url, {
live: true,
retry: true
});
this.setState({ isLoading: false });
return temp;
}).catch((err) => {
this.setState({ isLoading: false });
});
};
getListNoteFromDb = () => {
this.setState({ isLoading: true })
fetch("http://myipaddress:5984/dictionary")
.then(Response => Response.json())
.then(response => {
localNoteDb.info().then((resp) => {
console.log(JSON.stringify(resp))
//resp will contain disk_size
if (resp.doc_count !== response.doc_count) {
this.syncDb();
} else {
this.setState({ isLoading: false })
}
}).catch((err) => {
console.log("ERROR<<<<<<" + err);
});
});
}
getListNoteFromDbText = (txt) => {
this.setState({ text: txt, indicator: true, notfoundFlag: false })
clearTimeout(this.timer);
this.timer = setTimeout(function () {
localNoteDb
.allDocs({
include_docs: true,
attachments: true,
startkey: txt.toLowerCase(),
endkey: txt.toLowerCase() + '\ufff0'
}).then(function (result) {
if (result.rows.length > 0) {
// handle result
this.setState({
indicator: false,
arrNote1: result.rows.slice(0, 10)
})
clearTimeout(this.timer);
} else {
this.setState({
indicator: false,
notfoundFlag: true
})
}
}.bind(this))
.catch(err => {
this.setState({ isLoading: false })
Toast.show(err.message)
})
}.bind(this),
100
);
}
renderItem = ({ item }) => {
console.log("ITEMS....." + JSON.stringify(item));
return (
<TouchableHighlight
underlayColor={'#98c5ba'}
onPress={() => {
this.isAtCurrentScreen = false
this.props.addWordHistory(item.doc)
this.props.navigation.navigate('DetailsMeaning', {
idNote: item.doc,
})
}}
style={{ marginLeft: 10, marginTop: 3, marginRight: 10 }}
>
<Text numberOfLines={1} style={{ color: '#29282A', margin: 5, fontSize: 16, fontFamily: 'Roboto-Regular' }}>{item.doc._id}</Text>
</TouchableHighlight>
)
}
render() {
return this.state.isLoading ? <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#f3fffc' }}><ActivityIndicator size="large" color="#ff6a00" /><Text>Fetching Data Please wait...</Text></View> : <View style={{ flex: 1, backgroundColor: '#f3fffc', zIndex: 1 }}><View style={{ marginLeft: 15, marginRight: 15, zIndex: 2, marginTop: -28 }}>
<SearchBar
placeholder="Type Here..."
lightTheme={true}
color='black'
searchIcon={{ size: 30, color: '#3ea58d' }}
inputStyle={{ backgroundColor: 'white' }}
inputContainerStyle={{ backgroundColor: 'white', height: 30 }}
containerStyle={{ backgroundColor: 'white', borderWidth: 1, borderColor: '#3ea58d', borderRadius: 5 }}
onChangeText={(text) => this.getListNoteFromDbText(text)}
value={this.state.text}
/>
</View>
{this.state.text === '' ? <Text></Text> :
(this.state.indicator ? <View style={{ flex: 1 }}><ActivityIndicator size="large" color="#ff6a00" /></View> : <View style={{ flex: 1, flexDirection: 'column' }}><Text style={{ backgroundColor: '#98c5ba', textAlign: 'center', color: 'white', marginTop: 5, marginLeft: 15, marginRight: 15, borderRadius: 3, fontFamily: 'Roboto-Black' }}>RESULTS</Text>{this.state.notfoundFlag ? (<Text style={{ textAlign: 'center', color: 'black', marginTop: 50, fontSize: 21, fontWeight: 'bold', fontStyle: 'italic' }}>Not Found</Text>) : (<FlatList
style={{ backgroundColor: '#f3fffc', marginTop: 6 }}
data={this.state.arrNote1}
showsVerticalScrollIndicator={false}
keyExtractor={(item, index) => index.toString()}
renderItem={this.renderItem}
/>)}</View>)}
<View style={{ marginTop: 1, position: 'absolute', bottom: 0 }}>
<AdsBanner />
</View>
</View>
}
}
const mapStateToProps = (state) => {
return {
wordHistory: state.addHistory.wordDetails
}
}
const mapDispatchToProps = (dispatch) => {
return {
addWordHistory: (product) => dispatch({ type: 'ADD_WORD', payload: product })
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Home);
Base64 代码,我把链接放在索引中。
import {decode, encode} from 'base-64'
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
}
process.browser = true
它在调试模式下工作正常,但在发布模式下不行。
我有同样的问题
React Native atob() / btoa() 在没有远程 JS 调试的情况下无法工作
通过放置base64代码在调试模式下一切正常,但是当我这样做./gradlew assembleRelease
并测试apk时,数据无法加载。
在发布 apk 中也显示与上述相同的问题。
它与base64问题或任何其他问题有关吗?请帮忙。谢谢。
解决方案
推荐阅读
- esp8266 - 我无法使用 micropython 在 ESP8266/nodemcu 上获得 python 提示
- ruby - 将数组元素转换为哈希
- html - 货币转换器 - 当我按下按钮时没有任何反应
- hashids - 为什么哈希值可以被解码?
- string - 在python中使用字符串时的Min函数
- python - PythonAnywhere WSGI 报错(解决方法未找到如何设置是)
- python - 使用 BeautifulSoup 解析 HTML 结构
- clojure - 无法获得 datomic 客户端工件
- python - 如何使用 python、html.parser 和 regex 提取 url
- chef-infra - 如何在厨师中为当地的烹饪书编写包装烹饪书,而不依赖于厨师社区的厨师烹饪书?