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

Viewport argument key "viewport-fit" not recognized and ignored. #17

Open
RicoLiu opened this issue Jun 3, 2019 · 0 comments
Open

Viewport argument key "viewport-fit" not recognized and ignored. #17

RicoLiu opened this issue Jun 3, 2019 · 0 comments

Comments

@RicoLiu
Copy link
Owner

RicoLiu commented Jun 3, 2019

问题:
在 iOS 10 上报错:

Viewport argument key "viewport-fit" not recognized and ignored.

google 了一下发现是因为适配 iPhoneX 的刘海屏而导致的,这样的话,就需要对 iOS 11 做兼容性处理了。

解决:

    (function () {
      var viewportTag = null;
      var metaTags = document.getElementsByTagName('meta');
      for (var i = 0; i < metaTags.length; i++) {
          if (metaTags[i].getAttribute('name') === "viewport") {
              viewportTag = metaTags[i];
              break;
          }
      }
      if (!viewportTag) {
          viewportTag = document.createElement("meta");
          viewportTag.setAttribute('name', 'viewport');
      }
      
      var viewportTagContent = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0';
      
      // Detect if iOS device
      if (/(iPhone|iPod|iPad)/i.test(window.navigator.userAgent)) {
        // Get iOS major version
        var iosVersion = parseInt((window.navigator.userAgent).match(/OS (\d+)_(\d+)_?(\d+)? like Mac OS X/i)[1]);
        // Detect if device is running >iOS 11
        // iOS 11's UIWebView and WKWebView changes the viewport behaviour to render viewport without the status bar. Need to override with "viewport-fit: cover" to include the status bar.
        if (iosVersion >= 11) {
          viewportTagContent += ', viewport-fit=cover';
        }
      }
      
      // Update viewport tag attribute
      viewportTag.setAttribute('content', viewportTagContent);
    })()

参考引用:mapsplugin/cordova-plugin-googlemaps#1645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant