From 5fb764eb0f85b001ff80bdfe1389302f9419d46a Mon Sep 17 00:00:00 2001 From: kleinsea Date: Wed, 19 May 2021 18:09:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dios=E4=BF=9D=E5=AD=98p?= =?UTF-8?q?wa=E6=97=B6=E4=B8=8D=E8=83=BD=E6=AD=A3=E7=A1=AE=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=BA=94=E7=94=A8=E5=9B=BE=E6=A0=87=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 23 +++++++++++++++++++++-- src/utils/index.js | 4 ++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 3e10f681..620ac47b 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -import React, { Suspense } from "react"; +import React, { Suspense, useEffect } from "react"; import AuthRoute from "./middleware/AuthRoute"; import Navbar from "./component/Navbar/Navbar.js"; import useMediaQuery from "@material-ui/core/useMediaQuery"; @@ -8,7 +8,7 @@ import { useSelector } from "react-redux"; import { Redirect, Route, Switch, useRouteMatch } from "react-router-dom"; import Auth from "./middleware/Auth"; import { CssBaseline, makeStyles, ThemeProvider } from "@material-ui/core"; -import { changeThemeColor } from "./utils"; +import { changeThemeColor, isIOS } from "./utils"; import NotFound from "./component/Share/NotFound"; // Lazy loads import LoginForm from "./component/Login/LoginForm"; @@ -30,6 +30,7 @@ import ResetForm from "./component/Login/ResetForm"; import Reset from "./component/Login/Reset"; import PageLoading from "./component/Placeholder/PageLoading"; import CodeViewer from "./component/Viewer/Code"; +import axios from "axios"; const PDFViewer = React.lazy(() => import(/* webpackChunkName: "pdf" */ "./component/Viewer/PDF") ); @@ -81,6 +82,24 @@ export default function App() { const classes = useStyles(); const { path } = useRouteMatch(); + + useEffect(async () => { + // fix: ios下pwa icon没有生效 + if(!isIOS()) return false; + try { + const { data } = await axios.get("/manifest.json"); + const { head } = document; + if(data.icons && data.icons.length > 0 && head) { + let appendData = ""; + data.icons.map(iconData => { + appendData += ``; + }); + head.innerHTML += appendData; + } + } catch (error) { + console.log(error); + } + }, []); return ( diff --git a/src/utils/index.js b/src/utils/index.js index fc572b5b..d3f4bdce 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -185,6 +185,10 @@ export const isMac = () => { return navigator.platform.toUpperCase().indexOf("MAC") >= 0; }; +export const isIOS = () => { + return navigator.userAgent.toUpperCase().indexOf("IPHONE") >= 0; +}; + export function vhCheck() { const vh = window.innerHeight; document.documentElement.style.setProperty("--vh", `${vh}px`);