小编Abh*_*hek的帖子

react-native 如何使用链接打开本地文件 url?

我正在使用以下代码下载文件(可以是 PDF 或 DOC),然后使用链接打开它。

const { dirs } = RNFetchBlob.fs;
let config = {
    fileCache : true,
    appendExt : extension,
    addAndroidDownloads : {
        useDownloadManager : false,
        notification : false,
        title : 'File',
        description : 'A file.',
        path: `${dirs.DownloadDir}/file.${extension}`,
    },
};
RNFetchBlob.config(config)
    .fetch(
        method,
        remoteUrl,
        APIHelpers.getDefaultHeaders()
    )
    .then((res) => {
        let status = res.info().status;
        if (status == 200) {
            Linking.canOpenURL(res.path())
                .then((supported) => {
                    if (!supported) {
                        alert('Can\'t handle url: ' + res.path());
                    } else {
                        Linking.openURL(res.path())
                            .catch((err) => alert('An error occurred …
Run Code Online (Sandbox Code Playgroud)

android ios react-native react-native-linking rn-fetch-blob

6
推荐指数
2
解决办法
4938
查看次数