KSYReachability.h
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// KSYReachability.h
// KSYCommon
//
// Created by ksyun on 2017/1/4.
// Copyright © 2017年 ksyun. All rights reserved.
//
#ifndef _KSYReachability_H_
#define _KSYReachability_H_
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
/**
* Create NS_ENUM macro if it does not exist on the targeted version of iOS or OS X.
*
* @see http://nshipster.com/ns_enum-ns_options/
**/
#ifndef NS_ENUM
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
#endif
extern NSString *const kKSYReachabilityChangedNotification;
typedef NS_ENUM(NSInteger, KSYNetworkStatus) {
// same as Apple NetworkStatus
KSYNotReachable = 0,
KSYReachableViaWiFi = 2,
KSYReachableViaWWAN = 1
};
@class KSYReachability;
typedef void (^KSYNetworkReachable)(KSYReachability * reachability);
typedef void (^KSYNetworkUnreachable)(KSYReachability * reachability);
typedef void (^KSYNetworkReachability)(KSYReachability * reachability, SCNetworkConnectionFlags flags);
@interface KSYReachability : NSObject
@property (nonatomic, copy) KSYNetworkReachable reachableBlock;
@property (nonatomic, copy) KSYNetworkUnreachable unreachableBlock;
@property (nonatomic, copy) KSYNetworkReachability reachabilityBlock;
@property (nonatomic, assign) BOOL reachableOnWWAN;
+(instancetype)reachabilityWithHostname:(NSString*)hostname;
// This is identical to the function above, but is here to maintain
//compatibility with Apples original code. (see .m)
+(instancetype)reachabilityWithHostName:(NSString*)hostname;
+(instancetype)reachabilityForInternetConnection;
+(instancetype)reachabilityWithAddress:(void *)hostAddress;
+(instancetype)reachabilityForLocalWiFi;
-(instancetype)initWithReachabilityRef:(SCNetworkReachabilityRef)ref;
-(BOOL)startNotifier;
-(void)stopNotifier;
-(BOOL)isReachable;
-(BOOL)isReachableViaWWAN;
-(BOOL)isReachableViaWiFi;
// WWAN may be available, but not active until a connection has been established.
// WiFi may require a connection for VPN on Demand.
-(BOOL)isConnectionRequired; // Identical DDG variant.
-(BOOL)connectionRequired; // Apple's routine.
// Dynamic, on demand connection?
-(BOOL)isConnectionOnDemand;
// Is user intervention required?
-(BOOL)isInterventionRequired;
-(KSYNetworkStatus)currentReachabilityStatus;
-(SCNetworkReachabilityFlags)reachabilityFlags;
-(NSString*)currentReachabilityString;
-(NSString*)currentReachabilityFlags;
@end
#endif // _KSYReachability_H_