diff --git a/src/components/Layout/Footer.tsx b/src/components/Layout/Footer.tsx index 2256014..d2746db 100644 --- a/src/components/Layout/Footer.tsx +++ b/src/components/Layout/Footer.tsx @@ -10,34 +10,26 @@ export default function Footer() { const phoneLink = hotline.replace(/[^\d+]/g, '') const companyName = texts['footer.company'] || '成都阿美巴企业管理咨询有限公司' const address = String(config?.contact_address || '四川省成都市双流区正兴街道湖畔路北段366号1栋3楼1号').trim() - // Desktop falls back to AMap's web search. On phones use the operating system's - // map-navigation scheme so the user's installed/default map app handles the route. + // Desktop uses AMap's web search. iPhone Safari gets the native AMap scheme + // directly; an automatic web fallback can interrupt the app launch on iOS. const amapLink = `https://uri.amap.com/search?keyword=${encodeURIComponent(address)}&city=${encodeURIComponent('成都')}&view=map&src=ameiba` - const appleMapsLink = `https://maps.apple.com/?daddr=${encodeURIComponent(address)}&dirflg=d` + const iosAmapLink = `iosamap://path?sourceApplication=ameiba&dname=${encodeURIComponent(address)}&t=0` const openNavigation = (event: MouseEvent) => { const ua = window.navigator.userAgent const destination = encodeURIComponent(address) if (/Android/i.test(ua)) { event.preventDefault() window.location.href = `geo:0,0?q=${destination}` - } else if (/iPhone|iPad|iPod/i.test(ua)) { + } else if (/iPhone|iPad|iPod/i.test(ua) && /MicroMessenger/i.test(ua)) { event.preventDefault() - if (/MicroMessenger/i.test(ua)) { // WeChat blocks third-party app schemes on iOS. Give the visitor a useful // next step instead of leaving the tap with no visible response. void window.navigator.clipboard?.writeText(address).catch(() => undefined) window.alert('微信内无法直接唤起地图 App,地址已复制。请点击右上角“···”,选择“在 Safari 中打开”后再点击导航。') - return - } - // AMap's iOS scheme opens the installed AMap app and uses its current - // location as the starting point when only dname is supplied. - const openedAt = Date.now() - window.location.href = `iosamap://path?sourceApplication=ameiba&dname=${destination}&t=0` - window.setTimeout(() => { - if (!document.hidden && Date.now() - openedAt >= 1_000) window.location.href = appleMapsLink - }, 1_200) } } + const isIOS = typeof navigator !== 'undefined' && /iPhone|iPad|iPod/i.test(navigator.userAgent) + const navigationLink = isIOS ? iosAmapLink : amapLink return (