代码之家  ›  专栏  ›  技术社区  ›  Steve Madsen

How to determine if an iOS device has a cellular radio?

  •  3
  • Steve Madsen  · 技术社区  · 14 年前

    Is it possible, without including an exhaustive list of models in the code, to determine if an iOS device includes a cellular radio?

    我正在为一个应用程序添加一个主机可访问性检查,我希望失败消息适合这个设备。例如:

    A network connection is not available. Please join a Wi-Fi network or move to a location with better cellular reception.

    This is fine for iPhone and iPad 3G, but it's amateur for an iPod touch or iPad without 3G. For those devices, I'd like to remove mention of cellular service.

    I don't want to create an array in code of every iOS device that Apple has shipped that has a cellular radio.

    2 回复  |  直到 14 年前
        1
  •  1
  •   progrmr    14 年前

    There doesn't seem to be a way. Erica Sadun has an interesting UIDevice-hardware extension project on github but it can't determine whether there is cellular radio either.

        2
  •  1
  •   bentford Marko Hlebar    14 年前

    The best you can do is use the Apple provided sample project for Reachability.

    http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

    It has three states of the network status:

    typedef enum {
        NotReachable = 0,
        ReachableViaWiFi,
        ReachableViaWWAN
    } NetworkStatus;
    

    如果 ReachableViaWiFi 状态返回,不提蜂窝服务。

    This will be an improvement because even with a cellular radio you might in a wifi only location.