使用文档选取器获取路径后,iOS上的React-Native-pdf加载失败

时间:2019-11-28 18:10:16

标签: pdf react-native-pdf

我正在使用react-native-document-picker选择PDF。选择之后,我将文件的URI传递给react-native-pdf的PDF。 它返回此错误,但仅在iOS上。在Android中工作正常。 有什么建议吗?

ON ERROR --- Error: Load pdf failed. path=file:///private/var/mobile/Containers/Data/Application/250D8D83-5F0F-402C-912B-F1B199551218/tmp/com.yada.nen-Inbox/Bolletta%20Luce%20a2a.pdf
at createErrorFromErrorData (NativeModules.js:152)
at NativeModules.js:104
at MessageQueue.__invokeCallback (MessageQueue.js:442)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:343)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:80

这就是我选择PDF的方式:

static pickPDF = async (callBack,goBack=()=>{}) => {
    try {
        const res = await DocumentPicker.pick({
            type: [DocumentPicker.types.pdf],
        });
        console.log("URI of the uploaded PDF: ", res.uri);

        callBack(res.uri, res.name);
    } catch (err) {
        if (DocumentPicker.isCancel(err) ) {
            goBack();
        } else {
            throw err;
        }
    }
};

以下是我如何使用react-native-pdf显示PDF:

<Pdf
                    source={{uri:"file://"+this.state.pdfUri, cache: false}}
                    horizontal
                    page={page}
                    scrollEnabled={false}
                    onError={(error)=>{
                        console.log("ON ERROR ---",error);
                    }}
                    onPageChanged={this.onPageChanged}
                    style={flex}
                />

0 个答案:

没有答案