问题描述
我知道我似乎无法正常工作。已添加“ onFileDownload = {({nativeEvent:{downloadUrl}})=> {”,我需要自己的代码才能完成此工作。我试图使用expo文件系统和expo共享来下载此文件,但它不起作用。我想要的是,当他们下载pdf而不是预览时,他们可以共享或保存文档。任何帮助将不胜感激。
下面是我试图使其工作但失败的代码(警报功能起作用,但是什么也没发生):
import React,{ Component } from 'react';
import { StyleSheet,ActivityIndicator,View,Platform,PermissionsAndroid,Alert } from 'react-native';
import * as Permissions from 'expo-permissions';
import { WebView } from 'react-native-webview';
//sharing and download
import * as Sharing from 'expo-sharing';
import * as FileSystem from 'expo-file-system';
import { Image,Text,TouchableOpacity,} from 'react-native';
import * as ImagePicker from 'expo-image-picker';
export default function App() {
let [selectedImage,setSelectedImage] = React.useState(null);
let openImagePickerAsync = async () => {
const downloadResumable = FileSystem.createDownloadResumable(
{downloadUrl},${FileSystem.documentDirectory}/pdf.pdf,{},);
const { uri,status } = await downloadResumable.downloadAsync();
// setSelectedImage({ localUri: uri });
Sharing.shareAsync(uri);
};
let openShareDialogAsync = async () => {
if (!(await Sharing.isAvailableAsync())) {
alert(Uh oh,sharing isn't available on your platform);
return;
}
Sharing.shareAsync(selectedImage.localUri);
};
// if (selectedImage !== null) {
// return (
//
//
// Share this
//
//
// );
// }
return (
<View style={{ flex: 1 }}>
<WebView
style={{ flex: 1 }}
source={{ uri: 'http://www.pdf995.com/' }}
onFileDownload={ ( { nativeEvent: { downloadUrl } } ) => {
Alert.alert(
"Documents","Do you wish to download and share this document",[
{
text: "Download",onPress: () => {openImagePickerAsync}
},{
text: "Cancel",onPress: () => console.log("Cancel pressed"),style: "cancel"
},],{ cancelable: false }
);}
} />
</View>
);
}
我从博览会零食中获取了代码:https://snack.expo.io/@trinet/sharing 任何帮助将不胜感激。我真的很困
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)