import { View, Text, Modal, TouchableOpacity, Platform, Image, ActivityIndicator, } from "react-native"; import React, { useState } from "react"; import { useTailwind } from "tailwind-rn"; import { Button } from "@rneui/themed"; import * as Linking from "expo-linking"; import * as FileSystem from "expo-file-system"; import * as IntentLauncher from "expo-intent-launcher"; import Toast from "react-native-toast-message"; export default function UpdateModal({ visible, setVisible, data }) { const tailwind = useTailwind(); const [isInstalling, setIsInstalling] = useState(false); //安卓下载安装最新安装包 const downloadAndInstallAPK = async () => { setIsInstalling(true); const apkUrl = data.download_url; try { const downloadResumable = FileSystem.createDownloadResumable( apkUrl, `${FileSystem.documentDirectory}ironfans.apk` ); const { uri } = await downloadResumable.downloadAsync(); const localUri = await FileSystem.getContentUriAsync(uri); await IntentLauncher.startActivityAsync( "android.intent.action.INSTALL_PACKAGE", { data: localUri, flags: 1, } ); } catch (error) { Toast.show({ type: "error", text1: "安装失败,请前往官网下载" + error, topOffset: 60, }); } finally { setIsInstalling(false); } }; return ( 发现新版本 {data?.version} {data?.log} {!data?.force && ( setVisible(false)} style={tailwind("my-4")} > 暂不更新 )} ); }