[![Reference Status](https://www.versioneye.com/objective-c/reachability/reference_badge.svg?style=flat)](https://www.versioneye.com/objective-c/reachability/references)
# Reachability
This is a drop-in replacement for Apple's `Reachability` class. It is ARC-compatible, and it uses the new GCD methods to notify of network interface changes.
In addition to the standard `NSNotification`, it supports the use of blocks for when the network becomes reachable and unreachable.
Finally, you can specify whether a WWAN connection is considered "reachable".
*DO NOT OPEN BUGS UNTIL YOU HAVE TESTED ON DEVICE*
## Requirements
Once you have added the `.h/m` files to your project, simply:
* Go to the `Project->TARGETS->Build Phases->Link Binary With Libraries`.
* Press the plus in the lower left of the list.
* Add `SystemConfiguration.framework`.
Boom, you're done.
## Examples
### Block Example
This sample uses blocks to notify when the interface state has changed. The blocks will be called on a **BACKGROUND THREAD**, so you need to dispatch UI updates onto the main thread.
// Allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
// Set the blocks
reach.reachableBlock = ^(Reachability*reach)
{
// keep in mind this is called on a background thread
// and if you are updating the UI it needs to happen
// on the main thread, like this:
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"REACHABLE!");
});
};
reach.unreachableBlock = ^(Reachability*reach)
{
NSLog(@"UNREACHABLE!");
};
// Start the notifier, which will cause the reachability object to retain itself!
[reach startNotifier];
### `NSNotification` Example
This sample will use `NSNotification`s to notify when the interface has changed. They will be delivered on the **MAIN THREAD**, so you *can* do UI updates from within the function.
In addition, it asks the `Reachability` object to consider the WWAN (3G/EDGE/CDMA) as a non-reachable connection (you might use this if you are writing a video streaming app, for example, to save the user's data plan).
// Allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
// Tell the reachability that we DON'T want to be reachable on 3G/EDGE/CDMA
reach.reachableOnWWAN = NO;
// Here we set up a NSNotification observer. The Reachability that caused the notification
// is passed in the object parameter
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
[reach startNotifier];
## Tell the world
Head over to [Projects using Reachability](https://github.com/tonymillion/Reachability/wiki/Projects-using-Reachability) and add your project for "Maximum Wins!".
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Object-C_使用object-c开发的iOS平台网络框架_network.zip (71个子文件)
Object-C_使用object-c开发的iOS平台网络框架_network
.DS_Store 10KB
banner.png 227KB
MXNetworking-OC
MXNetworking+Information.m 3KB
.DS_Store 6KB
NSObject+MXSwizzle.m 2KB
MXNetworkingMethods.m 17KB
MXNetworking+Logs.m 5KB
MXNetworking+Information.h 2KB
MXNetworking+Parsing.h 1KB
NSJSONSerialization+RemovingNulls.h 954B
MXNetworkingMethods.h 12KB
MXNetworking+Logs.h 472B
NSJSONSerialization+RemovingNulls.m 3KB
NSObject+MXSwizzle.h 1KB
MXNetworking+Authorization.h 503B
MXNetworking.h 430B
MXNetworking+Authorization.m 2KB
RequestHeaderManager
RequestHeaderManager.h 502B
RequestHeaderManager.m 2KB
MXNetworingRequestCountManager.h 423B
NSMutableURLRequest+Headers.h 848B
MXNetworking+Parsing.m 4KB
NSMutableURLRequest+Headers.m 974B
MXNetworingRequestCountManager.m 1KB
banner.jpg 162KB
MXNetworking.podspec 6KB
README.md 2KB
MXNetworking-OC-Demo
.DS_Store 10KB
Podfile 289B
MXNetworking-OC-Demo.xcworkspace
contents.xcworkspacedata 238B
xcuserdata
Meniny.xcuserdatad
UserInterfaceState.xcuserstate 33KB
xcdebugger
Breakpoints_v2.xcbkptlist 91B
MXNetworking-OC-Demo.xcodeproj
project.pbxproj 24KB
xcuserdata
Meniny.xcuserdatad
xcschemes
MXNetworking-OC-Demo.xcscheme 3KB
xcschememanagement.plist 492B
project.xcworkspace
contents.xcworkspacedata 165B
xcuserdata
Meniny.xcuserdatad
UserInterfaceState.xcuserstate 9KB
Pods
Pods.xcodeproj
project.pbxproj 20KB
xcuserdata
Meniny.xcuserdatad
xcschemes
Pods-MXNetworking-OC-Demo.xcscheme 2KB
Reachability.xcscheme 2KB
xcschememanagement.plist 677B
.DS_Store 6KB
Manifest.lock 213B
Reachability
LICENCE.txt 1KB
Reachability.m 13KB
Reachability.h 3KB
README.md 3KB
Headers
.DS_Store 6KB
Private
Reachability
Reachability.h 3KB
Public
Reachability
Reachability.h 3KB
Target Support Files
.DS_Store 6KB
Reachability
Reachability.xcconfig 580B
Reachability-prefix.pch 48B
Reachability-dummy.m 128B
Pods-MXNetworking-OC-Demo
Pods-MXNetworking-OC-Demo-acknowledgements.markdown 1KB
Pods-MXNetworking-OC-Demo.release.xcconfig 595B
Pods-MXNetworking-OC-Demo.debug.xcconfig 595B
Pods-MXNetworking-OC-Demo-dummy.m 154B
Pods-MXNetworking-OC-Demo-frameworks.sh 3KB
Pods-MXNetworking-OC-Demo-acknowledgements.plist 2KB
Pods-MXNetworking-OC-Demo-resources.sh 5KB
MXNetworking-OC-Demo
ViewController.h 221B
Base.lproj
Main.storyboard 2KB
LaunchScreen.storyboard 2KB
AppDelegate.h 283B
AppDelegate.m 2KB
main.m 340B
ViewController.m 4KB
Info.plist 2KB
Assets.xcassets
AppIcon.appiconset
Contents.json 1KB
Podfile.lock 213B
共 71 条
- 1
资源评论
Ddddddd_158
- 粉丝: 734
- 资源: 206
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功