|
| 1 | +/* |
| 2 | + Copyright (c) 2011, Tony Million. |
| 3 | + All rights reserved. |
| 4 | + |
| 5 | + Redistribution and use in source and binary forms, with or without |
| 6 | + modification, are permitted provided that the following conditions are met: |
| 7 | + |
| 8 | + 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | + list of conditions and the following disclaimer. |
| 10 | + |
| 11 | + 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + this list of conditions and the following disclaimer in the documentation |
| 13 | + and/or other materials provided with the distribution. |
| 14 | + |
| 15 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 | + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | + POSSIBILITY OF SUCH DAMAGE. |
| 26 | + */ |
| 27 | + |
| 28 | +#import <Foundation/Foundation.h> |
| 29 | +#import <SystemConfiguration/SystemConfiguration.h> |
| 30 | + |
| 31 | +//! Project version number for MacOSReachability. |
| 32 | +FOUNDATION_EXPORT double ReachabilityVersionNumber; |
| 33 | + |
| 34 | +//! Project version string for MacOSReachability. |
| 35 | +FOUNDATION_EXPORT const unsigned char ReachabilityVersionString[]; |
| 36 | + |
| 37 | +/** |
| 38 | + * Create NS_ENUM macro if it does not exist on the targeted version of iOS or OS X. |
| 39 | + * |
| 40 | + * @see http://nshipster.com/ns_enum-ns_options/ |
| 41 | + **/ |
| 42 | +#ifndef NS_ENUM |
| 43 | +#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type |
| 44 | +#endif |
| 45 | + |
| 46 | +extern NSString *const kReachabilityChangedNotification; |
| 47 | + |
| 48 | +typedef NS_ENUM(NSInteger, NetworkStatus) { |
| 49 | + // Apple NetworkStatus Compatible Names. |
| 50 | + NotReachable = 0, |
| 51 | + ReachableViaWiFi = 2, |
| 52 | + ReachableViaWWAN = 1 |
| 53 | +}; |
| 54 | + |
| 55 | +@class Reachability; |
| 56 | + |
| 57 | +typedef void (^NetworkReachable)(Reachability * reachability); |
| 58 | +typedef void (^NetworkUnreachable)(Reachability * reachability); |
| 59 | +typedef void (^NetworkReachability)(Reachability * reachability, SCNetworkConnectionFlags flags); |
| 60 | + |
| 61 | + |
| 62 | +@interface Reachability : NSObject |
| 63 | + |
| 64 | +@property (nonatomic, copy) NetworkReachable reachableBlock; |
| 65 | +@property (nonatomic, copy) NetworkUnreachable unreachableBlock; |
| 66 | +@property (nonatomic, copy) NetworkReachability reachabilityBlock; |
| 67 | + |
| 68 | +@property (nonatomic, assign) BOOL reachableOnWWAN; |
| 69 | + |
| 70 | + |
| 71 | ++(instancetype)reachabilityWithHostname:(NSString*)hostname; |
| 72 | +// This is identical to the function above, but is here to maintain |
| 73 | +//compatibility with Apples original code. (see .m) |
| 74 | ++(instancetype)reachabilityWithHostName:(NSString*)hostname; |
| 75 | ++(instancetype)reachabilityForInternetConnection; |
| 76 | ++(instancetype)reachabilityWithAddress:(void *)hostAddress; |
| 77 | ++(instancetype)reachabilityForLocalWiFi; |
| 78 | ++(instancetype)reachabilityWithURL:(NSURL*)url; |
| 79 | + |
| 80 | +-(instancetype)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; |
| 81 | + |
| 82 | +-(BOOL)startNotifier; |
| 83 | +-(void)stopNotifier; |
| 84 | + |
| 85 | +-(BOOL)isReachable; |
| 86 | +-(BOOL)isReachableViaWWAN; |
| 87 | +-(BOOL)isReachableViaWiFi; |
| 88 | + |
| 89 | +// WWAN may be available, but not active until a connection has been established. |
| 90 | +// WiFi may require a connection for VPN on Demand. |
| 91 | +-(BOOL)isConnectionRequired; // Identical DDG variant. |
| 92 | +-(BOOL)connectionRequired; // Apple's routine. |
| 93 | +// Dynamic, on demand connection? |
| 94 | +-(BOOL)isConnectionOnDemand; |
| 95 | +// Is user intervention required? |
| 96 | +-(BOOL)isInterventionRequired; |
| 97 | + |
| 98 | +-(NetworkStatus)currentReachabilityStatus; |
| 99 | +-(SCNetworkReachabilityFlags)reachabilityFlags; |
| 100 | +-(NSString*)currentReachabilityString; |
| 101 | +-(NSString*)currentReachabilityFlags; |
| 102 | + |
| 103 | +@end |
0 commit comments