Coder Social home page Coder Social logo

ahreach's Introduction

AHReach

What?

AHReach is a simple reachability library for iOS. It covers roughly the same ground as the Reachability sample code written by Apple, but has a block-based API for notifying client code of changes and an explicitly liberal (MIT) license. It is also written with ARC projects in mind.

AHReach allows you to monitor for changes in network availability. This means you can preemptively notify your users when the device's connection is down, or when particular servers might not be available.

How?

AHReach uses the SystemConfiguration framework (in particular, the SCNetworkReachability API) to listen for changes in network availability and interface switchover (WiFi to WWAN, for example).

You can incorporate AHReach into your project by copy-pasting AHReach.h and AHReach.m into your project. You will also need to link against SystemConfiguration.framework if you aren't already.

Specific Examples

How to detect if the default host is reachable via any interface

AHReach *defaultHostReach = [AHReach reachForDefaultHost];
[defaultHostReach startUpdatingWithBlock:^(AHReach *reach) {
	if([reach isReachable])
		NSLog(@"Can reach default host");
}];

How to detect if an arbitrary Internet address is reachable via WiFi

struct sockaddr_in addr;
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_len = sizeof(struct sockaddr_in);
addr.sin_family = AF_INET;
addr.sin_port = htons(80);	
inet_aton("173.194.43.0", &addr.sin_addr);

AHReach *addressReach = [AHReach reachForAddress:&addr];
[addressReach startUpdatingWithBlock:^(AHReach *reach) {
	if([reach isReachableViaWiFi])
		NSLog(@"Can reach Google via WiFi");
}];

See the sample project for more examples.

ahreach's People

Contributors

warrenm avatar

Watchers

 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.