commit | author | age
|
e395b5
|
1 |
/* |
H |
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 WAReachabilityChangedNotification; |
|
47 |
|
|
48 |
typedef NS_ENUM(NSInteger, WANetworkStatus) { |
|
49 |
// Apple NetworkStatus Compatible Names. |
|
50 |
WANotReachable = 0, |
|
51 |
WAReachableViaWiFi = 2, |
|
52 |
WAReachableViaWWAN = 1 |
|
53 |
}; |
|
54 |
|
|
55 |
@class WAReachability; |
|
56 |
|
|
57 |
typedef void (^WANetworkReachable)(WAReachability * reachability); |
|
58 |
typedef void (^WANetworkUnreachable)(WAReachability * reachability); |
|
59 |
typedef void (^WANetworkReachability)(WAReachability * reachability, SCNetworkConnectionFlags flags); |
|
60 |
|
|
61 |
|
|
62 |
@interface WAReachability : NSObject |
|
63 |
|
|
64 |
@property (nonatomic, copy) WANetworkReachable reachableBlock; |
|
65 |
@property (nonatomic, copy) WANetworkUnreachable unreachableBlock; |
|
66 |
@property (nonatomic, copy) WANetworkReachability 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 |
|
|
79 |
-(instancetype)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; |
|
80 |
|
|
81 |
-(BOOL)startNotifier; |
|
82 |
-(void)stopNotifier; |
|
83 |
|
|
84 |
-(BOOL)isReachable; |
|
85 |
-(BOOL)isReachableViaWWAN; |
|
86 |
-(BOOL)isReachableViaWiFi; |
|
87 |
|
|
88 |
// WWAN may be available, but not active until a connection has been established. |
|
89 |
// WiFi may require a connection for VPN on Demand. |
|
90 |
-(BOOL)isConnectionRequired; // Identical DDG variant. |
|
91 |
-(BOOL)connectionRequired; // Apple's routine. |
|
92 |
// Dynamic, on demand connection? |
|
93 |
-(BOOL)isConnectionOnDemand; |
|
94 |
// Is user intervention required? |
|
95 |
-(BOOL)isInterventionRequired; |
|
96 |
|
|
97 |
-(WANetworkStatus)currentReachabilityStatus; |
|
98 |
-(SCNetworkReachabilityFlags)reachabilityFlags; |
|
99 |
-(NSString*)currentReachabilityString; |
|
100 |
-(NSString*)currentReachabilityFlags; |
|
101 |
|
|
102 |
@end |