Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复ios保存pwa时不能正确展示应用图标的问题 #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";
Expand All @@ -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")
);
Expand Down Expand Up @@ -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 += `<link rel="apple-touch-icon" sizes="${iconData.sizes.split(' ')[0]}" href="${iconData.src}">`;
});
head.innerHTML += appendData;
}
} catch (error) {
console.log(error);
}
}, []);
return (
<React.Fragment>
<ThemeProvider theme={theme}>
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down