react-native-android - 在发布版本 android 中显示 epub 的问题
问题描述
我尝试使用epubjs-rn包通过下面的代码显示我的 epub,在调试版本中一切正常,当我获得发布版本和测试时,epub book 不显示并在开始显示时修复加载,我在 android studio 控制台中调试并发现同样的错误:
I/ReactNativeJS: readBookEpub id: 4868
I/ReactNativeJS: source: http://localhost:8899/4868/
E/ReactNativeJS: Empty Response
我的代码:
_showEpub(bookName) {
console.log("_showEpub");
const targetPath = 'http://127.0.0.1:8899/' + bookName + '.epub';
//------------------------------------------------------show Epub
try {
this.streamer.start()
.then((origin) => {
console.log("Served from:", origin);
// this.streamer.check('http://127.0.0.1:8899/moby-dick.epub').then((t) => console.log("hiii"+t));
return this.streamer.get(targetPath);
})
.then((src) => {
console.log("Loading from:", src);
return this.setState({ urlBook: src });
});
}
catch (err) {
console.log("Error: " + err);
}
//---------------------------------------------------
}
对于 show book ,我从我的服务器下载 bookRNBackgroundDownloader
并保存,然后将其解压缩到资产文件夹以在本地阅读,我的解压缩功能:
_unZipBook(bookName) {
console.log("_unZipBook")
const sourcePath = Dirs.DocumentDir + '/FaraSource/e/' + bookName + '.zip';
const targetPath = `${Dirs.DocumentDir}/assets/${bookName}`;
unzip(sourcePath, targetPath)
.then((path) => {
console.log("unZip " + bookName + "in" + targetPath);
this._showEpub(bookName);
// return url;
})
}
任何人都可以帮助我解决这个问题吗?
解决方案
我解决了这个问题,必须在 AndroidManifest 中添加一行
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
推荐阅读
- r - 使用 qqggplot 更改 QQ 图中的线条颜色
- amazon-s3 - Terraform bucket_notification 抛出错误
- c# - Winforms Inhereted Control 阻止设计人员工作
- ios - UITableviewCell 中的 collectionView numberOfItemsInSection
- java - 如何在 elasticsearch 7.1 中更新文档
- r - 在列中查找连续短语的出现
- arcore - 缩放/缩放更大的 3D 模型
- google-cloud-platform - filter gcp web api 根据前缀获取磁盘列表
- accessibility - MacOS Mojave 上的语音快捷方式不起作用
- dojo - 道场 1.9。FilteringSelect ComboBox 滚动到最后选择的项目显示 [IE]