Git Product home page Git Product logo

fxreachability's Introduction

Purpose

FXReachability is a lightweight reachability class for Mac and iOS. It is designed to be as simple as possible, with no extraneous bells and whistles.

Supported iOS & SDK Versions

  • Supported build target - iOS 7.1 / Mac OS 10.9 (Xcode 5.1, Apple LLVM compiler 5.1)
  • Earliest supported deployment target - iOS 5.0 / Mac OS 10.7
  • Earliest compatible deployment target - iOS 4.3 / Mac OS 10.6

NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this iOS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.

ARC Compatibility

FXReachability works both with or without ARC without modification. There is no need to exclude FXReachability files from the ARC validation process, or to convert FXReachability using the ARC conversion tool.

Installation

To use FXReachability, just drag the class files into your project and add the SystemConfiguration framework to your build phases. FXReachability is a self-instantiating singleton, so there's no need to create an instance of it.

Usage

To use FXReachability, just add an observer for the FXReachabilityStatusDidChangeNotification notification, as follows:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myUpdateMethod:) name:FXReachabilityStatusDidChangeNotification object:nil];

In your notification handler method, you can then simply use the following code to determine if the device has a network connection:

BOOL reachable = [FXReachability isReachable];

Or to find out the exact status, use the following:

FXReachabilityStatus status = [FXReachability sharedInstance].status;

You can also poll this property at any time to determine the current status.

Methods

The FXReachability class has the following methods and properties:

+ (instancetype)sharedInstance;

This returns the singleton shared instance of the FXReachability class. Useful for accessing the status property.

+ (BOOL)isReachable;

This method returns YES if the device is reachable, and NO if it isn't. Note that reachability is inherently optimistic - a return value of NO means that you definitely can't make a network connection, but a value of YES only means that you may be able to (for example, the site you are trying to connect to may be down). For this reason, +isReachable will return YES if the status is currently unknown, to prevent spurious errors.

@property (nonatomic, readonly) FXReachabilityStatus status;

This property returns the current reachability status. For obvious reasons, it's read-only. For a list of possible status values, see below.

FXReachabilityStatus

The [FXReachability sharedInstance].status property is a constant which can have one of the following values:

FXReachabilityStatusUnknown

This means that the status is not currently known. This is usually the case prior to the first time that the FXReachabilityStatusDidChangeNotification has fired, but will not usually occur otherwise.

FXReachabilityStatusNotReachable

This means that the device does not currently have access to the internet.

FXReachabilityStatusReachableViaWWAN

This means that the device currently has a mobile data connection (e.g. 3G) and may therefore have poor bandwidth and/or metered data. You may wish to pause large downloads or reduce the quality of streaming video in this case. Note that this status is only supported on iOS devices - a Mac that is using a tethered connection or a 3G dongle will not report that this is the case.

FXReachabilityStatusReachableViaWiFi

This means that the device has either a WiFi or ethernet broadband connection, and can be presumed to have reasonable bandwidth and/or unmetered access. Note that a Mac will report that is has this status even if it is actually sharing a mobile data connection from an iPhone or 3G dongle.

Release Notes

Version 1.1.1

  • Now complies with -Weverything warning level

Version 1.1

  • Added +isReachable convenience method

Version 1.0

  • Initial release

fxreachability's People

Contributors

ishkawa avatar nicklockwood avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.