Skip to content

Commit b6a39a1

Browse files
committed
Merge pull request #92 from lintianzhi/feature/upstats
QNReachability
2 parents 2fc8777 + b1bc18d commit b6a39a1

File tree

6 files changed

+135
-134
lines changed

6 files changed

+135
-134
lines changed

QiniuSDK.xcodeproj/project.pbxproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
BA1659301BDBD6FB00C7304A /* QNStats.h in Headers */ = {isa = PBXBuildFile; fileRef = BA16592E1BDBD6FB00C7304A /* QNStats.h */; settings = {ASSET_TAGS = (); }; };
1717
BA1659311BDBD6FB00C7304A /* QNStats.m in Sources */ = {isa = PBXBuildFile; fileRef = BA16592F1BDBD6FB00C7304A /* QNStats.m */; settings = {ASSET_TAGS = (); }; };
1818
BA1659321BDBD6FB00C7304A /* QNStats.m in Sources */ = {isa = PBXBuildFile; fileRef = BA16592F1BDBD6FB00C7304A /* QNStats.m */; settings = {ASSET_TAGS = (); }; };
19-
BA1A40F61BE497E5009A5E00 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = BA1A40F51BE497E5009A5E00 /* Reachability.m */; settings = {ASSET_TAGS = (); }; };
19+
BA1A40FA1BF0B09C009A5E00 /* QNReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = BA1A40F91BF0B09C009A5E00 /* QNReachability.m */; settings = {ASSET_TAGS = (); }; };
2020
BA8408531BE250C80093B013 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA8408521BE250C80093B013 /* SystemConfiguration.framework */; };
2121
BA8408541BE251010093B013 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA8408521BE250C80093B013 /* SystemConfiguration.framework */; };
2222
DF0A03231B3BABEC00E3778C /* libQiniuSDK Mac.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DF2CDDFF19DAC05500CE01FB /* libQiniuSDK Mac.dylib */; };
@@ -141,8 +141,8 @@
141141
9A0CE9E3B1F13E790C38CB75 /* Pods-QiniuSDK iOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK iOSTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK iOSTests/Pods-QiniuSDK iOSTests.release.xcconfig"; sourceTree = "<group>"; };
142142
BA16592E1BDBD6FB00C7304A /* QNStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNStats.h; sourceTree = "<group>"; };
143143
BA16592F1BDBD6FB00C7304A /* QNStats.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNStats.m; sourceTree = "<group>"; };
144-
BA1A40F41BE497E5009A5E00 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Reachability.h; path = Reachability/Reachability.h; sourceTree = "<group>"; };
145-
BA1A40F51BE497E5009A5E00 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Reachability.m; path = Reachability/Reachability.m; sourceTree = "<group>"; };
144+
BA1A40F81BF0B09C009A5E00 /* QNReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QNReachability.h; path = QiniuSDK/QNReachability/QNReachability.h; sourceTree = "<group>"; };
145+
BA1A40F91BF0B09C009A5E00 /* QNReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QNReachability.m; path = QiniuSDK/QNReachability/QNReachability.m; sourceTree = "<group>"; };
146146
BA8408521BE250C80093B013 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; };
147147
C24CE1990894CD3CA9A17042 /* Pods-QiniuSDK iOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK iOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK iOSTests/Pods-QiniuSDK iOSTests.debug.xcconfig"; sourceTree = "<group>"; };
148148
DB8C25D8ADEC1AAEAFE9BB8A /* Pods-QiniuSDK iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK iOS/Pods-QiniuSDK iOS.debug.xcconfig"; sourceTree = "<group>"; };
@@ -288,13 +288,13 @@
288288
name = Frameworks;
289289
sourceTree = "<group>";
290290
};
291-
BA0FAD491BE25EB300DD5C51 /* Reachiability */ = {
291+
BA1A40F71BF0B079009A5E00 /* QNReachiability */ = {
292292
isa = PBXGroup;
293293
children = (
294-
BA1A40F41BE497E5009A5E00 /* Reachability.h */,
295-
BA1A40F51BE497E5009A5E00 /* Reachability.m */,
294+
BA1A40F81BF0B09C009A5E00 /* QNReachability.h */,
295+
BA1A40F91BF0B09C009A5E00 /* QNReachability.m */,
296296
);
297-
name = Reachiability;
297+
name = QNReachiability;
298298
sourceTree = "<group>";
299299
};
300300
DF293C9B19DBC2AE00799011 /* Http */ = {
@@ -320,6 +320,7 @@
320320
DF2CDDF619DAC05500CE01FB = {
321321
isa = PBXGroup;
322322
children = (
323+
BA1A40F71BF0B079009A5E00 /* QNReachiability */,
323324
DF2CDE4D19DAC6A400CE01FB /* QiniuSDK */,
324325
DF2CDE6F19DAE90300CE01FB /* QiniuSDKTests */,
325326
DF2CDE0019DAC05500CE01FB /* Products */,
@@ -342,7 +343,6 @@
342343
DF2CDE4D19DAC6A400CE01FB /* QiniuSDK */ = {
343344
isa = PBXGroup;
344345
children = (
345-
BA0FAD491BE25EB300DD5C51 /* Reachiability */,
346346
DFA9B65519E0B53700A15FD1 /* Recorder */,
347347
DF293C9B19DBC2AE00799011 /* Http */,
348348
DF2CDE4E19DAC6A400CE01FB /* Common */,
@@ -796,8 +796,8 @@
796796
DF293CA719DC05B800799011 /* QNHttpManager.m in Sources */,
797797
DF293CAC19DC0E5300799011 /* QNResumeUpload.m in Sources */,
798798
DF437CDC1B2429E10099587B /* QNUpToken.m in Sources */,
799-
BA1A40F61BE497E5009A5E00 /* Reachability.m in Sources */,
800799
DFF525341A6235D100D02BA1 /* QNSessionManager.m in Sources */,
800+
BA1A40FA1BF0B09C009A5E00 /* QNReachability.m in Sources */,
801801
DFA39AA719F1272800A1A158 /* QNAsyncRun.m in Sources */,
802802
DFA9B64B19E0018800A15FD1 /* QNUploadOption.m in Sources */,
803803
DF2CDE6B19DAC6A400CE01FB /* QNUploadManager.m in Sources */,

QiniuSDK/Http/QNStats.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
#import "HappyDns.h"
1414

1515
#if TARGET_OS_IPHONE
16-
#import "Reachability.h"
16+
#import "QNReachability.h"
1717
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
1818
#endif
1919

2020
@interface QNStats : NSObject
2121

2222
#if TARGET_OS_IPHONE
23-
@property (nonatomic, readonly) Reachability *wifiReach;
23+
@property (nonatomic, readonly) QNReachability *wifiReach;
2424
@property (nonatomic, readonly) CTTelephonyNetworkInfo *telephonyInfo;
25-
@property (atomic, readonly) NetworkStatus reachabilityStatus;
25+
@property (atomic, readonly) QNNetworkStatus reachabilityStatus;
2626
#endif
2727

2828
@property (nonatomic,retain) NSTimer *pushTimer;

QiniuSDK/Http/QNStats.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if TARGET_OS_IPHONE
1010
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
11-
#import "Reachability.h"
11+
#import "QNReachability.h"
1212
#endif
1313

1414
//#import "GZIP.h"
@@ -127,16 +127,16 @@ - (instancetype) initWithPushInterval: (int) interval
127127
}];
128128

129129
// WiFi, WLAN, or nothing
130-
_wifiReach = [Reachability reachabilityForInternetConnection];
130+
_wifiReach = [QNReachability reachabilityForInternetConnection];
131131
_reachabilityStatus = _wifiReach.currentReachabilityStatus;
132132

133-
[NSNotificationCenter.defaultCenter addObserverForName:kReachabilityChangedNotification
133+
[NSNotificationCenter.defaultCenter addObserverForName:kQNReachabilityChangedNotification
134134
object:nil
135135
queue:nil
136136
usingBlock:^(NSNotification *note) {
137137
_reachabilityStatus = _wifiReach.currentReachabilityStatus;
138138

139-
if (_reachabilityStatus != NotReachable) {
139+
if (_reachabilityStatus != QNNotReachable) {
140140
[self getOutIp];
141141
}
142142
}];
@@ -203,7 +203,7 @@ - (void) pushStats {
203203
@synchronized(self) {
204204

205205
#if TARGET_OS_IPHONE
206-
if (_reachabilityStatus == NotReachable) {
206+
if (_reachabilityStatus == QNNotReachable) {
207207
return;
208208
}
209209
#endif
@@ -278,9 +278,9 @@ - (NSString *) getSIP {
278278

279279
- (NSString *) getNetType {
280280
#if TARGET_OS_IPHONE
281-
if (_reachabilityStatus == ReachableViaWiFi) {
281+
if (_reachabilityStatus == QNReachableViaWiFi) {
282282
return @"wifi";
283-
} else if (_reachabilityStatus == ReachableViaWWAN) {
283+
} else if (_reachabilityStatus == QNReachableViaWWAN) {
284284
return @"wan";
285285
}
286286
#elif TARGET_OS_MAC
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
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+
32+
/**
33+
* Create NS_ENUM macro if it does not exist on the targeted version of iOS or OS X.
34+
*
35+
* @see http://nshipster.com/ns_enum-ns_options/
36+
**/
37+
#ifndef NS_ENUM
38+
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
39+
#endif
40+
41+
42+
typedef NS_ENUM (NSInteger, QNNetworkStatus) {
43+
// Apple NetworkStatus Compatible Names.
44+
QNNotReachable = 0,
45+
QNReachableViaWiFi = 2,
46+
QNReachableViaWWAN = 1
47+
};
48+
49+
extern NSString *const kQNReachabilityChangedNotification;
50+
51+
@class QNReachability;
52+
53+
typedef void (^NetworkReachable)(QNReachability * reachability);
54+
typedef void (^NetworkUnreachable)(QNReachability * reachability);
55+
56+
57+
@interface QNReachability : NSObject
58+
59+
@property (nonatomic, copy) NetworkReachable reachableBlock;
60+
@property (nonatomic, copy) NetworkUnreachable unreachableBlock;
61+
62+
@property (nonatomic, assign) BOOL reachableOnWWAN;
63+
64+
65+
+(QNReachability*)reachabilityWithHostname:(NSString*)hostname;
66+
// This is identical to the function above, but is here to maintain
67+
//compatibility with Apples original code. (see .m)
68+
+(QNReachability*)reachabilityWithHostName:(NSString*)hostname;
69+
+(QNReachability*)reachabilityForInternetConnection;
70+
+(QNReachability*)reachabilityWithAddress:(void *)hostAddress;
71+
+(QNReachability*)reachabilityForLocalWiFi;
72+
73+
-(QNReachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref;
74+
75+
-(BOOL)startNotifier;
76+
-(void)stopNotifier;
77+
78+
-(BOOL)isReachable;
79+
-(BOOL)isReachableViaWWAN;
80+
-(BOOL)isReachableViaWiFi;
81+
82+
// WWAN may be available, but not active until a connection has been established.
83+
// WiFi may require a connection for VPN on Demand.
84+
-(BOOL)isConnectionRequired; // Identical DDG variant.
85+
-(BOOL)connectionRequired; // Apple's routine.
86+
// Dynamic, on demand connection?
87+
-(BOOL)isConnectionOnDemand;
88+
// Is user intervention required?
89+
-(BOOL)isInterventionRequired;
90+
91+
-(QNNetworkStatus)currentReachabilityStatus;
92+
-(SCNetworkReachabilityFlags)reachabilityFlags;
93+
-(NSString*)currentReachabilityString;
94+
-(NSString*)currentReachabilityFlags;
95+
96+
@end

QiniuSDK/Reachability/Reachability.m renamed to QiniuSDK/QNReachability/QNReachability.m

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2525
POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727

28-
#import "Reachability.h"
28+
#import "QNReachability.h"
2929

3030
#import <sys/socket.h>
3131
#import <netinet/in.h>
@@ -35,10 +35,10 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3535
#import <netdb.h>
3636

3737

38-
NSString *const kReachabilityChangedNotification = @"kReachabilityChangedNotification";
38+
NSString *const kQNReachabilityChangedNotification = @"kQNReachabilityChangedNotification";
3939

4040

41-
@interface Reachability ()
41+
@interface QNReachability ()
4242

4343
@property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef;
4444
@property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue;
@@ -73,7 +73,7 @@ static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRea
7373
{
7474
#pragma unused (target)
7575

76-
Reachability *reachability = ((__bridge Reachability*)info);
76+
QNReachability *reachability = ((__bridge QNReachability*)info);
7777

7878
// We probably don't need an autoreleasepool here, as GCD docs state each queue has its own autorelease pool,
7979
// but what the heck eh?
@@ -84,16 +84,16 @@ static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRea
8484
}
8585

8686

87-
@implementation Reachability
87+
@implementation QNReachability
8888

8989
#pragma mark - Class Constructor Methods
9090

91-
+(Reachability*)reachabilityWithHostName:(NSString*)hostname
91+
+(QNReachability*)reachabilityWithHostName:(NSString*)hostname
9292
{
93-
return [Reachability reachabilityWithHostname:hostname];
93+
return [QNReachability reachabilityWithHostname:hostname];
9494
}
9595

96-
+(Reachability*)reachabilityWithHostname:(NSString*)hostname
96+
+(QNReachability*)reachabilityWithHostname:(NSString*)hostname
9797
{
9898
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]);
9999
if (ref)
@@ -106,7 +106,7 @@ +(Reachability*)reachabilityWithHostname:(NSString*)hostname
106106
return nil;
107107
}
108108

109-
+(Reachability *)reachabilityWithAddress:(void *)hostAddress
109+
+(QNReachability *)reachabilityWithAddress:(void *)hostAddress
110110
{
111111
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);
112112
if (ref)
@@ -119,7 +119,7 @@ +(Reachability *)reachabilityWithAddress:(void *)hostAddress
119119
return nil;
120120
}
121121

122-
+(Reachability *)reachabilityForInternetConnection
122+
+(QNReachability *)reachabilityForInternetConnection
123123
{
124124
struct sockaddr_in zeroAddress;
125125
bzero(&zeroAddress, sizeof(zeroAddress));
@@ -129,7 +129,7 @@ +(Reachability *)reachabilityForInternetConnection
129129
return [self reachabilityWithAddress:&zeroAddress];
130130
}
131131

132-
+(Reachability*)reachabilityForLocalWiFi
132+
+(QNReachability*)reachabilityForLocalWiFi
133133
{
134134
struct sockaddr_in localWifiAddress;
135135
bzero(&localWifiAddress, sizeof(localWifiAddress));
@@ -144,7 +144,7 @@ +(Reachability*)reachabilityForLocalWiFi
144144

145145
// Initialization methods
146146

147-
-(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref
147+
-(QNReachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref
148148
{
149149
self = [super init];
150150
if (self != nil)
@@ -382,19 +382,19 @@ -(BOOL)isInterventionRequired
382382

383383
#pragma mark - reachability status stuff
384384

385-
-(NetworkStatus)currentReachabilityStatus
385+
-(QNNetworkStatus)currentReachabilityStatus
386386
{
387387
if([self isReachable])
388388
{
389389
if([self isReachableViaWiFi])
390-
return ReachableViaWiFi;
390+
return QNReachableViaWiFi;
391391

392392
#if TARGET_OS_IPHONE
393-
return ReachableViaWWAN;
393+
return QNReachableViaWWAN;
394394
#endif
395395
}
396396

397-
return NotReachable;
397+
return QNNotReachable;
398398
}
399399

400400
-(SCNetworkReachabilityFlags)reachabilityFlags
@@ -411,14 +411,14 @@ -(SCNetworkReachabilityFlags)reachabilityFlags
411411

412412
-(NSString*)currentReachabilityString
413413
{
414-
NetworkStatus temp = [self currentReachabilityStatus];
414+
QNNetworkStatus temp = [self currentReachabilityStatus];
415415

416-
if(temp == ReachableViaWWAN)
416+
if(temp == QNReachableViaWWAN)
417417
{
418418
// Updated for the fact that we have CDMA phones now!
419419
return NSLocalizedString(@"Cellular", @"");
420420
}
421-
if (temp == ReachableViaWiFi)
421+
if (temp == QNReachableViaWiFi)
422422
{
423423
return NSLocalizedString(@"WiFi", @"");
424424
}
@@ -452,7 +452,7 @@ -(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags
452452

453453
// this makes sure the change notification happens on the MAIN THREAD
454454
dispatch_async(dispatch_get_main_queue(), ^{
455-
[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification
455+
[[NSNotificationCenter defaultCenter] postNotificationName:kQNReachabilityChangedNotification
456456
object:self];
457457
});
458458
}

0 commit comments

Comments
 (0)