This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
/
TDReachability.h
64 lines (48 loc) · 2.42 KB
/
TDReachability.h
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
//
// TDReachability.h
// TouchDB
//
// Created by Jens Alfke on 2/13/12.
// Copyright (c) 2012 Couchbase, Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#ifdef GNUSTEP
typedef uint32_t SCNetworkReachabilityFlags;
typedef void* SCNetworkReachabilityRef;
typedef void* CFRunLoopRef;
#else
#import <SystemConfiguration/SCNetworkReachability.h>
#endif
typedef void (^TDReachabilityOnChangeBlock)(void);
/** Asynchronously tracks the reachability of an Internet host, using the SystemConfiguration framework's reachability API.
You can get called when reachability changes by either KV-observing the properties, or setting an "onChange" block.
"Reachable" means simply that the local IP stack has resolved the host's DNS name and knows how to route packets toward its IP address. It does NOT guarantee that you can successfully connect. Generally it just means that you have an Internet connection. */
@interface TDReachability : NSObject
{
NSString* _hostName;
SCNetworkReachabilityRef _ref;
CFRunLoopRef _runLoop;
SCNetworkReachabilityFlags _reachabilityFlags;
BOOL _reachabilityKnown;
TDReachabilityOnChangeBlock _onChange;
}
- (id) initWithHostName: (NSString*)hostName;
@property (readonly, nonatomic) NSString* hostName;
/** Starts tracking reachability.
You have to call this after creating the object, or none of its properties will change. The current thread must have a runloop.
@return YES if tracking started, or NO if there was an error. */
- (BOOL) start;
/** Stops tracking reachability.
This is called automatically by -dealloc, but to be safe you can call it when you release your TDReachability instance, to make sure that in case of a leak it isn't left running forever. */
- (void) stop;
/** YES if the host's reachability has been determined, NO if it hasn't yet or if there was an error. */
@property (readonly, nonatomic) BOOL reachabilityKnown;
/** The exact reachability flags; see Apple docs for the meanings of the bits. */
@property (readonly, nonatomic) SCNetworkReachabilityFlags reachabilityFlags;
/** Is this host reachable via a currently active network interface? */
@property (readonly) BOOL reachable;
/** Is this host reachable by WiFi (or wired Ethernet)? */
@property (readonly) BOOL reachableByWiFi;
/** If you set this, the block will be called whenever the reachability related properties change. */
@property (copy) TDReachabilityOnChangeBlock onChange;
@end