iPhone SDK Internet connection detection

后端 未结 3 2014
执念已碎
执念已碎 2020-12-02 05:33

I\'m working on an iPhone application that makes a few calls to web services. I posted this application on the Apple store but it got rejected (and rightly so) since there w

相关标签:
3条回答
  • 2020-12-02 05:45

    Cautionary word: beware SBUsesNetwork. I would personally love to know where SBUsesNetwork originally came from, because it's not mentioned anywhere in Apple's docs that I can find. When I add the key to my app's plist (as a boolean) and set to true, it doesn't seem to affect the behaviour of my app -- I get no warning about airplane mode, whether starting app completely afresh, or foregrounding a previous launch that was backgrounded.

    My app has UIRequiresPersistentWifi set to true, which appears to also do the job people claim SBUsesNetwork does (plus other things!).

    (I'm running iOS4.2.1 on an iPhone 4, XCode 3.2.5 64 bit).

    0 讨论(0)
  • 2020-12-02 05:53

    Apple Developer Connection has a sample application (Reachability) that uses the System Configuration framework to determine network status. It will tell you whether you have a WiFi, EDGE/3G or no Internet connection.

    You would use portions of this code in your application to determine network state, and then provide interface cues if no connection is available, such as a UIAlertView.

    0 讨论(0)
  • 2020-12-02 06:00

    If your application must have network access the easiest way is to add the following settings to your info.plist as boolean values.

    • SBUsesNetwork - Ensure the device has an active connection (Edit: not applicable, this seems to be a private API someone found at some point. It is not in Apple's developer documentation.)
    • UIRequiresPersistentWiFi - Ensures the device is connected via WiFi

    If your choice is not true then the user will be presented with an appropriate message when starting your application. Best of all this message is from the OS and thus is localized.

    If your application cannot download data from a website while running (loss of signal, site down) you should still warn the user though and not just spin indefinitely.

    0 讨论(0)
提交回复
热议问题