-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetConnection.h
46 lines (41 loc) · 1.31 KB
/
NetConnection.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
/**
* NetConnection is a small class responsible for keeping track of when your
* computer has access to the internet. It does so via the isOnline method
* and posting notifications to the NSNotificiationCenter.
*
* @author leebyron lee@leebyron.com
*
*
* To determine at any time if you are online
*
* BOOL live = [[NetConnection netConnection] isOnline];
*
*
* To keep track of net connection change events, subscribe to the event via
* the NSNotificationCenter:
*
* NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
* [nc addObserver:self
* selector:@selector(netConnectionChanged:)
* name:kNetConnectionChangeNotification
* object:[NetConnection netConnection]];
*
* - (void)netConnectionChanged:(NSNotification*)notif {
* BOOL live = [[NetConnection netConnection] isOnline];
* }
*
*/
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <ApplicationServices/ApplicationServices.h>
#define kNetConnectionChangeNotification @"NetConnectionChangeNotification"
@interface NetConnection : NSObject {
SCDynamicStoreRef dynamicStore;
CFRunLoopSourceRef runLoopSource;
BOOL isOnline;
NSURL* connectivityURL;
}
+ (NetConnection*)netConnection;
- (BOOL)isOnline;
@end