【问题标题】:PHP mobile detection with new iPadOS/iOS 13使用新 iPadOS/iOS 13 进行 PHP 移动检测
【发布时间】:2020-02-25 07:30:25
【问题描述】:

我想知道是否有任何文档或任何新库可以检测到新的 iPadOS / iOS 13?

他们曾经输出:

mozilla/5.0 (ipad; cpu iphone os 12_1_3 like mac os x) applewebkit/605.1.15 (khtml, like gecko) version/12.0 mobile/15e148 safari/604.1

但现在正在输出:

mozilla/5.0 (macintosh; intel mac os x 10_15) applewebkit/605.1.15 (khtml, like gecko) version/13.0.1 safari/605.1.15

有人遇到过这个吗?有什么新的库可以使用吗?

【问题讨论】:

标签: php ios ipad http-referer


【解决方案1】:

我得到的最佳解决方案是使用 javascript:

// iPad check
if( (window.screen.height / window.screen.width == 1024 / 768) || 
    (window.screen.height / window.screen.width == 1112 / 834) ||
    (window.screen.height / window.screen.width == 1366 / 1024)
) {
    // do stuff here
}

不是以前的预期,而是我拥有的最佳解决方案。

【讨论】:

    【解决方案2】:

    无法找到一种 php 方法,但使用 javascript 这似乎是最合适的 首先检测设备是否是移动设备。在最近的 iOS for iPad 中,此检查返回 false,这实际上是错误的,但这是由于桌面用户代理造成的。 第二次测试设备是否具有触摸属性并查看平台是否包含“MacIntel”字符串

    let isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); 
    let isIOSMobile = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;                                          
    if (!isMobile && isIOSMobile ) {   
        //Desktop mode on IPad detected      
        alert("For the best experience we recommend switching Safari view to mobile"); 
    }
    

    【讨论】:

      【解决方案3】:

      这是一个 php 解决方案,对我来说效果很好:

      <?php
      //Detect special conditions devices
      $iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
      $iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
      $iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
      $iPadOS  = stripos($_SERVER['HTTP_USER_AGENT'],"Macintosh");
      $Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
      
      //TODO
      if( $iPod || $iPhone || $iPad || $iPadOS || $Android){
      //your methods
      }
      

      【讨论】:

      • 这在 iPadOS 13 中有效吗?我没有得到任何与 iPad 匹配的内容
      • @markb 你注意到这条线了吗:$iPadOS = stripos($_SERVER['HTTP_USER_AGENT'],"Macintosh");?
      • 是的,但它也会匹配 macOS 上的设备,例如 Safari
      • 没错,但这是迄今为止唯一的方法,您可以添加媒体屏幕尺寸以使其更安全
      猜你喜欢
      • 1970-01-01
      • 2020-02-17
      • 2012-12-20
      • 2013-04-24
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2021-04-20
      • 2017-06-20
      相关资源
      最近更新 更多