Ver código fonte

fix: 修改navigator 为undefined

Before 6 meses atrás
pai
commit
32eb32cfab

+ 6 - 6
src/app/[locale]/(TabBar)/[[...share]]/_home/DownloadSection.tsx

@@ -1,13 +1,17 @@
 "use client";
 import { Link } from "@/i18n/routing";
 import { useEffect, useState } from "react";
+function isWebView() {
+    const userAgent = window.navigator && navigator.userAgent;
 
+    return /WebView|iPhone|iPod|Android/.test(userAgent);
+}
 const DownloadSection = () => {
     const [visible, setVisible] = useState<boolean>(true);
 
     useEffect(() => {
         const isCloseDownload = sessionStorage.getItem("isCloseDownload");
-        if (isCloseDownload) {
+        if (isWebView() || isCloseDownload) {
             setVisible(false);
         }
     }, []);
@@ -16,12 +20,8 @@ const DownloadSection = () => {
         sessionStorage.setItem("isCloseDownload", "true");
         setVisible(false);
     };
-    function isWebView() {
-        const userAgent = navigator.userAgent;
 
-        return /WebView|iPhone|iPod|Android/.test(userAgent);
-    }
-    if (!visible || isWebView()) return null;
+    if (!visible) return null;
     return (
         <div
             className={"relative flex items-center px-[0.1389rem] py-[0.0694rem]"}