【问题标题】:PWA icon does not appear while adding to home screen using SAFARI使用 SAFARI 添加到主屏幕时不显示 PWA 图标
【发布时间】:2019-12-07 09:24:50
【问题描述】:

我正在使用 ReactJs 开发 PWA,并且已经尝试了两天来解决这个问题,但没有!我在 package.json 中正确添加了指令块。这里的离子问题是我的应用程序的徽标在添加到主屏幕时会字面上显示在 android 上。但是,当我尝试使用 Safari 将应用程序添加到 iOS 上的主屏幕时,徽标不会出现!这变得令人沮丧。请帮忙!我已经使用应安装应用程序的 SSL 证书(随处建议)保护了域,但它不起作用。这是我的 package.json:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "homepage": "https://app.mydomain.com"
}

这是我的 index.html 头:

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, viewport-fit=cover">
    <meta name="theme-color" content="#f8f9fa"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta name="apple-mobile-web-app-title" content="myappname">
    <link href="https://cdn.rawgit.com/rastikerdar/vazir-font/v20.1.0/dist/font-face.css" rel="stylesheet" type="text/css" />

    <link rel="shortcut icon" href="{{ url('/images/icons/icon-120×120.png') }}">

<link rel="apple-touch-icon" sizes="72×72" href="{{ url('/images/icons/icon-72×72.png') }}">
<link rel="apple-touch-icon" sizes="96×96" href="{{ url('/images/icons/icon-96×96.png') }}">
<link rel="apple-touch-icon" sizes="120×120" href="{{ url('/images/icons/icon-120×120.png') }}">
<link rel="apple-touch-icon" sizes="128×128" href="{{ url('/images/icons/icon-128×128.png') }}">
<link rel="apple-touch-icon" sizes="144×144" href="{{ url('/images/icons/icon-144×144.png') }}">
<link rel="apple-touch-icon" sizes="152×152" href="{{ url('/images/icons/icon-152×152.png') }}">
<link rel="apple-touch-icon" sizes="167×167" href="{{ url('/images/icons/icon-167×167.png') }}">
<link rel="apple-touch-icon" sizes="180×180" href="{{ url('/images/icons/icon-180×180.png') }}">
<link rel="apple-touch-icon" sizes="192×192" href="{{ url('/images/icons/icon-192×192.png') }}">
<link rel="apple-touch-icon" sizes="384×384" href="{{ url('/images/icons/icon-384×384.png') }}">
<link rel="apple-touch-icon" sizes="512×512" href="{{ url('/images/icons/icon-512×512.png') }}">


<link rel="icon" sizes="72×72" href="{{ url('/images/icons/icon-72×72.png') }}">
<link rel="icon" sizes="96×96" href="{{ url('/images/icons/icon-96×96.png') }}">
<link rel="icon" sizes="128×128" href="{{ url('/images/icons/icon-128×128.png') }}">
<link rel="icon" sizes="144×144" href="{{ url('/images/icons/icon-144×144.png') }}">
<link rel="icon" sizes="152×152" href="{{ url('/images/icons/icon-152×152.png') }}">
<link rel="icon" sizes="192×192" href="{{ url('/images/icons/icon-192×192.png') }}">
<link rel="icon" sizes="384×384" href="{{ url('/images/icons/icon-384×384.png') }}">
<link rel="icon" sizes="512×512" href="{{ url('/images/icons/icon-512×512.png') }}">



    <link rel="manifest" href="./manifest.json"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"/>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />

    <title>React App</title>
  </head>

【问题讨论】:

  • 不是 100% 确定,但我会首先尝试从路径中删除角 {{-brakets。 Header/Meta-Tags 通常不在 Angular 上下文中,因此不会被模板引擎评估。
  • 另外——我认为你不需要 url() 语法——这通常是 css 语法。
  • 另外 - 为了理解你的 pwa - 不是 package.json 而是 manifest.json 会很有用... pwa 的重要配置内容在哪里... 最有可能的图标配置在那里也是。
  • 感谢您的回复@Florian,我测试也没有用。它适用于Android,这很奇怪。我相信 Safari 一定有一些令人讨厌的修复...

标签: reactjs progressive-web-apps


【解决方案1】:

嗯...我唯一能想到的可能是您的前导“/”,如果它是相对路径,它应该是“./”。或者您的设备尺寸不正确...这是我在 iphone 7 和 10 以及一些 iPad 上测试的 pwa head-config。你可以试试https://forgetech.github.io/fg-vlv-pwa/#/anmeldung

<head>
  <meta charset="utf-8">
  <title>MeinVLV</title>
  <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
  <meta name="viewport"
    content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=no, minimum-scale=1.0, maximum-scale=5.0">

  <link rel="icon" type="image/x-icon" href="assets/images/favicon.ico">

  <link rel="apple-touch-icon" sizes="57x57" href="assets/images/application/apple-icon-57x57.png" />
  <link rel="apple-touch-icon" sizes="60x60" href="assets/images/application/apple-icon-60x60.png" />
  <link rel="apple-touch-icon" sizes="72x72" href="assets/images/application/apple-icon-72x72.png" />
  <link rel="apple-touch-icon" sizes="76x76" href="assets/images/application/apple-icon-76x76.png" />
  <link rel="apple-touch-icon" sizes="114x114" href="assets/images/application/apple-icon-114x114.png" />
  <link rel="apple-touch-icon" sizes="120x120" href="assets/images/application/apple-icon-120x120.png" />
  <link rel="apple-touch-icon" sizes="144x144" href="assets/images/application/apple-icon-144x144.png" />
  <link rel="apple-touch-icon" sizes="152x152" href="assets/images/application/apple-icon-152x152.png" />
  <link rel="apple-touch-icon" sizes="180x180" href="assets/images/application/apple-icon-180x180.png" />

  <!-- https://www.netguru.com/codestories/few-tips-that-will-make-your-pwa-on-ios-feel-like-native -->
  <!-- https://appsco.pe/developer/splash-screens -->
  <!-- https://stackoverflow.com/questions/12643817/ios-iphone-web-app-splash-screen-not-showing-up -->
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <link href="assets/images/application/iphone5_splash.png" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/iphone6_splash.png" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/iphoneplus_splash.png" media="(device-width: 621px) and (device-height: 1104px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/iphonex_splash.png" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/iphonexr_splash.png" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/iphonexsmax_splash.png" media="(device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/ipad_splash.png" media="(device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/ipadpro1_splash.png" media="(device-width: 834px) and (device-height: 1112px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/ipadpro3_splash.png" media="(device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />
  <link href="assets/images/application/ipadpro2_splash.png" media="(device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image" />

  <link rel="icon" type="image/png" sizes="32x32" href="assets/images/application/favicon-32x32.png" />
  <link rel="icon" type="image/png" sizes="16x16" href="assets/images/application/favicon-16x16.png" />
  <link rel="icon" type="image/png" sizes="96x96" href="assets/images/application/favicon-96x96.png" />
  <link rel="icon" type="image/png" sizes="192x192" href="assets/images/application/android-icon-192x192.png" />

  <meta name="msapplication-TileColor" content="#ffffff">
  <meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
  <meta name="theme-color" content="#ffffff">

  <link rel="manifest" href="manifest.json">
  <meta name="theme-color" content="#1976d2">
</head>

这是我的清单文件:

{
  "name": "MeinVLV - Github Dev Deployment",
  "short_name": "MeinVlv",
  "theme_color": "#0093c4",
  "background_color": "#fafafa",
  "display": "standalone",
  "scope": "/",
  "start_url": "https://forgetech.github.io/fg-vlv-pwa/",
  "icons": [
    {
      "src": "assets/images/application/pwa-icon-72x72.png",
      "sizes": "72x72",
      "type": "image/png"
    },
    {
      "src": "assets/images/application/pwa-icon-96x96.png",
      "sizes": "96x96",
      "type": "image/png"
    },
    {
      "src": "assets/images/application/pwa-icon-128x128.png",
      "sizes": "128x128",
      "type": "image/png"
    },
    {
      "src": "assets/images/application/pwa-icon-144x144.png",
      "sizes": "144x144",
      "type": "image/png"
    },
    {
      "src": "assets/images/application/pwa-icon-152x152.png",
      "sizes": "152x152",
      "type": "image/png"
    },
    {
      "src": "assets/images/application/pwa-icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "assets/images/application/pwa-icon-384x384.png",
      "sizes": "384x384",
      "type": "image/png"
    },
    {
      "src": "assets/images/application/pwa-icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ]
}

【讨论】:

  • 仍然没有修复。我已经仔细添加了你建议的所有内容。我想知道为什么它适用于 Android 而不是 iOS...
  • 天哪!多么愚蠢的错误。你不会相信的!要作为 iOS 徽标加载的文件应正确命名,referring to this
猜你喜欢
  • 1970-01-01
  • 2021-05-13
  • 2020-09-28
  • 1970-01-01
  • 1970-01-01
  • 2017-11-07
  • 2018-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多