【发布时间】:2022-12-23 15:18:37
【问题描述】:
我正在尝试从 url 下载 zip,但 RNFetchBlob 告诉我我有一个先前的响应待处理并使应用程序崩溃。
这是我调用 fetch 的函数
const downloadFile = async () => {
const dirs = RNFetchBlob.fs.dirs;
const response = await RNFetchBlob.config({
fileCache: true,
appendExt: 'zip',
path: dirs.DownloadDir + '/files/icons.zip',
addAndroidDownloads: {
title: dirs.DownloadDir + '/files/icons.zip',
description: `Download ${dirs.DownloadDir + '/files/icons.zip'}`,
useDownloadManager: false,
notification: false,
},
}).fetch('GET', BASE_URL + 'iconos');
console.log(response.path());
console.log(response);
return response;
};
在这里我检查权限
const checkPermission = async () => {
if (Platform.OS === 'ios') {
const response = await downloadFile();
return response;
} else {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'Storage Permission Required',
message: 'Application needs access to your storage to download File',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// Start downloading
const response = await downloadFile();
console.log('Storage Permission Granted.');
return response;
} else {
// If permission denied then show alert
Alert.alert('Error', 'Storage Permission Not Granted');
}
} catch (err) {
// To handle permission related exception
console.log('++++' + err);
}
}
};
这是我的 redux reducer
export const getIcons = () => {
return async dispatch => {
dispatch(fetching());
try {
const response = await checkPermission();
dispatch(getResponseSuccess(response));
} catch (error) {
dispatch(getResponseFailure());
}
};
};
当应用程序在 checkPermission 中执行下载文件时捕获并出现错误
++++错误:由于java.lang.IllegalStateException而取消:无法发出新请求,因为先前的响应仍然打开:请 调用 response.close()
【问题讨论】:
-
你有什么解决方法吗?
标签: javascript reactjs react-native react-redux redux-toolkit