Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3746afc

Browse files
committed
网络监听库更新
1 parent 1844b3c commit 3746afc

32 files changed

+522
-307
lines changed

‎.DS_Store

2 KB
Binary file not shown.

‎CocoaAsyncSocket_TCP.xcodeproj/project.pbxproj

Lines changed: 114 additions & 102 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

‎CocoaAsyncSocket_TCP/.DS_Store

0 Bytes
Binary file not shown.

‎CocoaAsyncSocket_TCP/Comon/.DS_Store

2 KB
Binary file not shown.

‎CocoaAsyncSocket_TCP/Comon/NetworkObserver/Connection/LocalConnection.h renamed to ‎CocoaAsyncSocket_TCP/Comon/NetworkObserver/RealReachability/Connection/LocalConnection.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#import <Foundation/Foundation.h>
1010
#import <SystemConfiguration/SystemConfiguration.h>
1111

12-
#define GLocalConnection [LocalConnection sharedInstance]
13-
1412
/// We post self to this notification,
1513
/// then you should invoke currentLocalConnectionStatus method to fetch current status.
1614
extern NSString *const kLocalConnectionChangedNotification;
@@ -28,12 +26,12 @@ typedef NS_ENUM(NSInteger, LocalConnectionStatus)
2826

2927
@interface LocalConnection : NSObject
3028

31-
+ (instancetype)sharedInstance;
29+
/// Newly added property for KVO usage:
30+
/// maybe you only want to observe the local network is available or not.
31+
@property (nonatomic, assign) BOOL isReachable;
3232

3333
/**
3434
* Start observering local connection status.
35-
*
36-
* @return success or failure. YES->success
3735
*/
3836
- (void)startNotifier;
3937

‎CocoaAsyncSocket_TCP/Comon/NetworkObserver/Connection/LocalConnection.m renamed to ‎CocoaAsyncSocket_TCP/Comon/NetworkObserver/RealReachability/Connection/LocalConnection.m

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@interface LocalConnection ()
2323
@property (assign, nonatomic) SCNetworkReachabilityRef reachabilityRef;
2424
@property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue;
25+
@property (nonatomic, assign) BOOL isNotifying;
2526

2627
-(void)localConnectionChanged;
2728
@end
@@ -101,6 +102,13 @@ + (instancetype)sharedInstance
101102

102103
- (void)startNotifier
103104
{
105+
if (self.isNotifying)
106+
{
107+
return;
108+
}
109+
110+
self.isNotifying = YES;
111+
104112
SCNetworkReachabilityContext context = { 0, NULL, NULL, NULL, NULL };
105113
context.info = (__bridge void *)self;
106114

@@ -119,6 +127,9 @@ - (void)startNotifier
119127
}
120128

121129
// First time we come in, notify the initialization of local connection.
130+
131+
self.isReachable = [self _isReachable];
132+
122133
__weak __typeof(self)weakSelf = self;
123134
dispatch_async(dispatch_get_main_queue(), ^{
124135
__strong __typeof(weakSelf)strongSelf = weakSelf;
@@ -129,6 +140,13 @@ - (void)startNotifier
129140

130141
-(void)stopNotifier
131142
{
143+
if (!self.isNotifying)
144+
{
145+
return;
146+
}
147+
148+
self.isNotifying = NO;
149+
132150
// First: stop any callbacks.
133151
SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL);
134152

@@ -139,7 +157,7 @@ -(void)stopNotifier
139157
#pragma mark - outside invoke
140158
- (LocalConnectionStatus)currentLocalConnectionStatus
141159
{
142-
if ([self isReachable])
160+
if ([self _isReachable])
143161
{
144162
if ([self isReachableViaWiFi])
145163
{
@@ -160,6 +178,8 @@ - (LocalConnectionStatus)currentLocalConnectionStatus
160178

161179
- (void)localConnectionChanged
162180
{
181+
self.isReachable = [self _isReachable];
182+
163183
// this makes sure the change notification happens on the MAIN THREAD
164184
__weak __typeof(self)weakSelf = self;
165185
dispatch_async(dispatch_get_main_queue(), ^{
@@ -189,7 +209,8 @@ -(SCNetworkReachabilityFlags)reachabilityFlags
189209

190210
#pragma mark - LocalReachability
191211

192-
- (BOOL)isReachable
212+
/// added underline prefix to distinguish the method from the property "isReachable"
213+
- (BOOL)_isReachable
193214
{
194215
SCNetworkReachabilityFlags flags;
195216

‎CocoaAsyncSocket_TCP/Comon/NetworkObserver/FSM/FSMEngine.m renamed to ‎CocoaAsyncSocket_TCP/Comon/NetworkObserver/RealReachability/FSM/FSMEngine.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ - (NSInteger)receiveInput:(NSDictionary *)dic
5959

6060
RRStateID previousStateID = self.currentStateID;
6161
self.currentStateID = newStateID;
62-
NSLog(@"curStateID is %@", @(self.currentStateID));
62+
//NSLog(@"curStateID is %@", @(self.currentStateID));
6363

6464
return (previousStateID == self.currentStateID) ? -1 : 0;
6565
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /