代码之家  ›  专栏  ›  技术社区  ›  Batgar

如何检测iPhone OS设备是否有接近传感器?

  •  2
  • Batgar  · 技术社区  · 16 年前

    与接近感测相关的文档指出,如果在没有接近感测器(即iPod touch、iPad)的设备上使用接近感测API,它们将像接近感测器启动一样返回。

    除了检查[uidevice currentdevice].model]字符串和“iphone”、“ipod touch”或“ipad”的解析之外,是否有更巧妙的方法来确定给定设备上是否有接近传感器?

    3 回复  |  直到 11 年前
        1
  •  3
  •   Claus Broch    16 年前

    摘自uidevice文档:

    近距离监控

    一个布尔值,指示 近程监控已启用(是) 或不(不)。

    讨论

    并非所有的iphone操作系统设备都有 接近传感器。以确定 提供近距离监控, 尝试启用它。如果 ProximityState属性仍然存在 不,近距离监控 可用。

    克劳斯

        2
  •  2
  •   David Gelhar    16 年前

    苹果文档指出,并非所有的iphone操作系统设备都有接近传感器。要确定应用程序运行的设备是否支持邻近性监视,请将proximitymonitoringenabled属性设置为yes,然后检查其值:

    UIDevice *device = [UIDevice currentDevice];
    device.proximityMonitoringEnabled = YES;
    if (device.proximityMonitoringEnabled == YES)
        // do something
    

    来源: http://www.mobileorchard.com/new-in-iphone-30-tutorial-series-part-4-proximity-detection/

        3
  •  0
  •   Tasos K. Sagar Jaybhay    11 年前

    也许这个片段会有帮助:

    -(BOOL) hasProximitySensor {
    
        UIDevice *dev = [UIDevice currentDevice];
        BOOL oldValue = [dev isProximityMonitoringEnabled];
        [dev setProximityMonitoringEnabled:!oldValue];
        BOOL newValue = [dev isProximityMonitoringEnabled];
    
        [dev setProximityMonitoringEnabled:oldValue];
    
        return (oldValue != newValue);
    }