cordova-plugin-mserviceinterface-2.0 1.0.26 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -28
- package/plugin.xml +153 -153
- package/src/android/CallbackProgressDialog.java +53 -53
- package/src/android/FileProvider.java +7 -7
- package/src/android/backgroundNotification.java +120 -120
- package/src/android/doubleogradle.gradle +5 -5
- package/src/android/mInterface.java +2123 -2087
- package/src/android/mInterfaceReceiver.java +59 -59
- package/src/android/mInterfaceService.java +749 -749
- package/src/android/mInterfaceUtil.java +1686 -1686
- package/src/android/res/xml/network_security_config.xml +8 -8
- package/src/android/res/xml/opener_paths.xml +16 -16
- package/src/ios/InternetConnection.h +64 -64
- package/src/ios/InternetConnection.m +242 -242
- package/src/ios/SSZipArchive.h +146 -146
- package/src/ios/SSZipArchive.m +1180 -1180
- package/src/ios/SSZipCommon.h +66 -66
- package/src/ios/UICKeyChainStore.h +64 -64
- package/src/ios/UICKeyChainStore.m +434 -434
- package/src/ios/XMLConverter.h +61 -61
- package/src/ios/XMLConverter.m +243 -243
- package/src/ios/ZipArchive.h +19 -19
- package/src/ios/aes/aes.h +270 -270
- package/src/ios/aes/aes_ni.c +687 -687
- package/src/ios/aes/aes_ni.h +59 -59
- package/src/ios/aes/aescrypt.c +301 -301
- package/src/ios/aes/aeskey.c +554 -554
- package/src/ios/aes/aesopt.h +776 -776
- package/src/ios/aes/aestab.c +418 -418
- package/src/ios/aes/aestab.h +173 -173
- package/src/ios/aes/brg_endian.h +127 -127
- package/src/ios/aes/brg_types.h +191 -191
- package/src/ios/aes/fileenc.c +145 -145
- package/src/ios/aes/fileenc.h +121 -121
- package/src/ios/aes/hmac.c +209 -209
- package/src/ios/aes/hmac.h +119 -119
- package/src/ios/aes/prng.c +155 -155
- package/src/ios/aes/prng.h +82 -82
- package/src/ios/aes/pwd2key.c +181 -181
- package/src/ios/aes/pwd2key.h +45 -45
- package/src/ios/aes/sha1.c +283 -283
- package/src/ios/aes/sha1.h +72 -72
- package/src/ios/minizip/crypt.c +146 -146
- package/src/ios/minizip/crypt.h +66 -66
- package/src/ios/minizip/ioapi.c +353 -353
- package/src/ios/minizip/ioapi.h +154 -154
- package/src/ios/minizip/ioapi_buf.c +452 -452
- package/src/ios/minizip/ioapi_buf.h +52 -52
- package/src/ios/minizip/ioapi_mem.c +167 -167
- package/src/ios/minizip/ioapi_mem.h +52 -52
- package/src/ios/minizip/minishared.c +292 -292
- package/src/ios/minizip/minishared.h +50 -50
- package/src/ios/minizip/unzip.c +2007 -2007
- package/src/ios/minizip/unzip.h +254 -254
- package/src/ios/minizip/zip.c +2007 -2007
- package/src/ios/minizip/zip.h +215 -215
- package/www/mInterface.js +3 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<network-security-config>
|
|
3
|
-
<base-config cleartextTrafficPermitted="true">
|
|
4
|
-
<trust-anchors>
|
|
5
|
-
<certificates src="system" />
|
|
6
|
-
</trust-anchors>
|
|
7
|
-
</base-config>
|
|
8
|
-
</network-security-config>
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<network-security-config>
|
|
3
|
+
<base-config cleartextTrafficPermitted="true">
|
|
4
|
+
<trust-anchors>
|
|
5
|
+
<certificates src="system" />
|
|
6
|
+
</trust-anchors>
|
|
7
|
+
</base-config>
|
|
8
|
+
</network-security-config>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<!-- https://developer.android.com/reference/android/support/v4/content/FileProvider.html#SpecifyFiles -->
|
|
3
|
-
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
|
4
|
-
<!-- cordova.file.dataDirectory -->
|
|
5
|
-
<files-path name="files" path="." />
|
|
6
|
-
<!-- cordova.file.cacheDirectory -->
|
|
7
|
-
<cache-path name="cache" path="." />
|
|
8
|
-
<!-- cordova.file.externalDataDirectory -->
|
|
9
|
-
<external-files-path name="external-files" path="." />
|
|
10
|
-
<!-- cordova.file.externalCacheDirectory -->
|
|
11
|
-
<external-cache-path name="external-cache" path="." />
|
|
12
|
-
<!-- cordova.file.externalRootDirectory -->
|
|
13
|
-
<external-path name="external" path="." />
|
|
14
|
-
<!-- Support for sdcard -->
|
|
15
|
-
<root-path name="root" path="." />
|
|
16
|
-
</paths>
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- https://developer.android.com/reference/android/support/v4/content/FileProvider.html#SpecifyFiles -->
|
|
3
|
+
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
|
4
|
+
<!-- cordova.file.dataDirectory -->
|
|
5
|
+
<files-path name="files" path="." />
|
|
6
|
+
<!-- cordova.file.cacheDirectory -->
|
|
7
|
+
<cache-path name="cache" path="." />
|
|
8
|
+
<!-- cordova.file.externalDataDirectory -->
|
|
9
|
+
<external-files-path name="external-files" path="." />
|
|
10
|
+
<!-- cordova.file.externalCacheDirectory -->
|
|
11
|
+
<external-cache-path name="external-cache" path="." />
|
|
12
|
+
<!-- cordova.file.externalRootDirectory -->
|
|
13
|
+
<external-path name="external" path="." />
|
|
14
|
+
<!-- Support for sdcard -->
|
|
15
|
+
<root-path name="root" path="." />
|
|
16
|
+
</paths>
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2016 Apple Inc. All Rights Reserved.
|
|
3
|
-
See LICENSE.txt for this sample’s licensing information
|
|
4
|
-
|
|
5
|
-
Abstract:
|
|
6
|
-
Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
#import <Foundation/Foundation.h>
|
|
10
|
-
#import <SystemConfiguration/SystemConfiguration.h>
|
|
11
|
-
#import <netinet/in.h>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
typedef enum : NSInteger {
|
|
15
|
-
NotReachable = 0,
|
|
16
|
-
ReachableViaWiFi,
|
|
17
|
-
ReachableViaWWAN
|
|
18
|
-
} NetworkStatus;
|
|
19
|
-
|
|
20
|
-
#pragma mark IPv6 Support
|
|
21
|
-
//Reachability fully support IPv6. For full details, see ReadMe.md.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
extern NSString *kReachabilityChangedNotification;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@interface InternetConnection : NSObject
|
|
28
|
-
|
|
29
|
-
/*!
|
|
30
|
-
* Use to check the reachability of a given host name.
|
|
31
|
-
*/
|
|
32
|
-
+ (instancetype)reachabilityWithHostName:(NSString *)hostName;
|
|
33
|
-
|
|
34
|
-
/*!
|
|
35
|
-
* Use to check the reachability of a given IP address.
|
|
36
|
-
*/
|
|
37
|
-
+ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress;
|
|
38
|
-
|
|
39
|
-
/*!
|
|
40
|
-
* Checks whether the default route is available. Should be used by applications that do not connect to a particular host.
|
|
41
|
-
*/
|
|
42
|
-
+ (instancetype)reachabilityForInternetConnection;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
#pragma mark reachabilityForLocalWiFi
|
|
46
|
-
//reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information.
|
|
47
|
-
//+ (instancetype)reachabilityForLocalWiFi;
|
|
48
|
-
|
|
49
|
-
/*!
|
|
50
|
-
* Start listening for reachability notifications on the current run loop.
|
|
51
|
-
*/
|
|
52
|
-
- (BOOL)startNotifier;
|
|
53
|
-
- (void)stopNotifier;
|
|
54
|
-
|
|
55
|
-
- (NetworkStatus)currentReachabilityStatus;
|
|
56
|
-
|
|
57
|
-
/*!
|
|
58
|
-
* WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand.
|
|
59
|
-
*/
|
|
60
|
-
- (BOOL)connectionRequired;
|
|
61
|
-
|
|
62
|
-
@end
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016 Apple Inc. All Rights Reserved.
|
|
3
|
+
See LICENSE.txt for this sample’s licensing information
|
|
4
|
+
|
|
5
|
+
Abstract:
|
|
6
|
+
Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import <SystemConfiguration/SystemConfiguration.h>
|
|
11
|
+
#import <netinet/in.h>
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
typedef enum : NSInteger {
|
|
15
|
+
NotReachable = 0,
|
|
16
|
+
ReachableViaWiFi,
|
|
17
|
+
ReachableViaWWAN
|
|
18
|
+
} NetworkStatus;
|
|
19
|
+
|
|
20
|
+
#pragma mark IPv6 Support
|
|
21
|
+
//Reachability fully support IPv6. For full details, see ReadMe.md.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
extern NSString *kReachabilityChangedNotification;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@interface InternetConnection : NSObject
|
|
28
|
+
|
|
29
|
+
/*!
|
|
30
|
+
* Use to check the reachability of a given host name.
|
|
31
|
+
*/
|
|
32
|
+
+ (instancetype)reachabilityWithHostName:(NSString *)hostName;
|
|
33
|
+
|
|
34
|
+
/*!
|
|
35
|
+
* Use to check the reachability of a given IP address.
|
|
36
|
+
*/
|
|
37
|
+
+ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress;
|
|
38
|
+
|
|
39
|
+
/*!
|
|
40
|
+
* Checks whether the default route is available. Should be used by applications that do not connect to a particular host.
|
|
41
|
+
*/
|
|
42
|
+
+ (instancetype)reachabilityForInternetConnection;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
#pragma mark reachabilityForLocalWiFi
|
|
46
|
+
//reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information.
|
|
47
|
+
//+ (instancetype)reachabilityForLocalWiFi;
|
|
48
|
+
|
|
49
|
+
/*!
|
|
50
|
+
* Start listening for reachability notifications on the current run loop.
|
|
51
|
+
*/
|
|
52
|
+
- (BOOL)startNotifier;
|
|
53
|
+
- (void)stopNotifier;
|
|
54
|
+
|
|
55
|
+
- (NetworkStatus)currentReachabilityStatus;
|
|
56
|
+
|
|
57
|
+
/*!
|
|
58
|
+
* WWAN may be available, but not active until a connection has been established. WiFi may require a connection for VPN on Demand.
|
|
59
|
+
*/
|
|
60
|
+
- (BOOL)connectionRequired;
|
|
61
|
+
|
|
62
|
+
@end
|
|
63
|
+
|
|
64
|
+
|
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (C) 2016 Apple Inc. All Rights Reserved.
|
|
3
|
-
See LICENSE.txt for this sample’s licensing information
|
|
4
|
-
|
|
5
|
-
Abstract:
|
|
6
|
-
Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
#import <arpa/inet.h>
|
|
10
|
-
#import <ifaddrs.h>
|
|
11
|
-
#import <netdb.h>
|
|
12
|
-
#import <sys/socket.h>
|
|
13
|
-
#import <netinet/in.h>
|
|
14
|
-
|
|
15
|
-
#import <CoreFoundation/CoreFoundation.h>
|
|
16
|
-
|
|
17
|
-
#import "InternetConnection.h"
|
|
18
|
-
|
|
19
|
-
#pragma mark IPv6 Support
|
|
20
|
-
//Reachability fully support IPv6. For full details, see ReadMe.md.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotification";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
#pragma mark - Supporting functions
|
|
27
|
-
|
|
28
|
-
#define kShouldPrintReachabilityFlags 1
|
|
29
|
-
|
|
30
|
-
static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment)
|
|
31
|
-
{
|
|
32
|
-
#if kShouldPrintReachabilityFlags
|
|
33
|
-
|
|
34
|
-
/* NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n",
|
|
35
|
-
(flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-',
|
|
36
|
-
(flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-',
|
|
37
|
-
|
|
38
|
-
(flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-',
|
|
39
|
-
(flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-',
|
|
40
|
-
(flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-',
|
|
41
|
-
(flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-',
|
|
42
|
-
(flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-',
|
|
43
|
-
(flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-',
|
|
44
|
-
(flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-',
|
|
45
|
-
comment
|
|
46
|
-
);*/
|
|
47
|
-
#endif
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info)
|
|
52
|
-
{
|
|
53
|
-
#pragma unused (target, flags)
|
|
54
|
-
NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback");
|
|
55
|
-
NSCAssert([(__bridge NSObject*) info isKindOfClass: [InternetConnection class]], @"info was wrong class in ReachabilityCallback");
|
|
56
|
-
|
|
57
|
-
InternetConnection* noteObject = (__bridge InternetConnection *)info;
|
|
58
|
-
// Post a notification to notify the client that the network reachability changed.
|
|
59
|
-
[[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
#pragma mark - Reachability implementation
|
|
64
|
-
|
|
65
|
-
@implementation InternetConnection
|
|
66
|
-
{
|
|
67
|
-
SCNetworkReachabilityRef _reachabilityRef;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
+ (instancetype)reachabilityWithHostName:(NSString *)hostName
|
|
71
|
-
{
|
|
72
|
-
InternetConnection* returnValue = NULL;
|
|
73
|
-
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]);
|
|
74
|
-
if (reachability != NULL)
|
|
75
|
-
{
|
|
76
|
-
returnValue= [[self alloc] init];
|
|
77
|
-
if (returnValue != NULL)
|
|
78
|
-
{
|
|
79
|
-
returnValue->_reachabilityRef = reachability;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
CFRelease(reachability);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return returnValue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
+ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress
|
|
90
|
-
{
|
|
91
|
-
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, hostAddress);
|
|
92
|
-
|
|
93
|
-
InternetConnection* returnValue = NULL;
|
|
94
|
-
|
|
95
|
-
if (reachability != NULL)
|
|
96
|
-
{
|
|
97
|
-
returnValue = [[self alloc] init];
|
|
98
|
-
if (returnValue != NULL)
|
|
99
|
-
{
|
|
100
|
-
returnValue->_reachabilityRef = reachability;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
CFRelease(reachability);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return returnValue;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
+ (instancetype)reachabilityForInternetConnection
|
|
111
|
-
{
|
|
112
|
-
struct sockaddr_in zeroAddress;
|
|
113
|
-
bzero(&zeroAddress, sizeof(zeroAddress));
|
|
114
|
-
zeroAddress.sin_len = sizeof(zeroAddress);
|
|
115
|
-
zeroAddress.sin_family = AF_INET;
|
|
116
|
-
|
|
117
|
-
return [self reachabilityWithAddress: (const struct sockaddr *) &zeroAddress];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
#pragma mark reachabilityForLocalWiFi
|
|
121
|
-
//reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information.
|
|
122
|
-
//+ (instancetype)reachabilityForLocalWiFi
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
#pragma mark - Start and stop notifier
|
|
127
|
-
|
|
128
|
-
- (BOOL)startNotifier
|
|
129
|
-
{
|
|
130
|
-
BOOL returnValue = NO;
|
|
131
|
-
SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL};
|
|
132
|
-
|
|
133
|
-
if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context))
|
|
134
|
-
{
|
|
135
|
-
if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode))
|
|
136
|
-
{
|
|
137
|
-
returnValue = YES;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return returnValue;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
- (void)stopNotifier
|
|
146
|
-
{
|
|
147
|
-
if (_reachabilityRef != NULL)
|
|
148
|
-
{
|
|
149
|
-
SCNetworkReachabilityUnscheduleFromRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
- (void)dealloc
|
|
155
|
-
{
|
|
156
|
-
[self stopNotifier];
|
|
157
|
-
if (_reachabilityRef != NULL)
|
|
158
|
-
{
|
|
159
|
-
CFRelease(_reachabilityRef);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
#pragma mark - Network Flag Handling
|
|
165
|
-
|
|
166
|
-
- (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags
|
|
167
|
-
{
|
|
168
|
-
PrintReachabilityFlags(flags, "networkStatusForFlags");
|
|
169
|
-
if ((flags & kSCNetworkReachabilityFlagsReachable) == 0)
|
|
170
|
-
{
|
|
171
|
-
// The target host is not reachable.
|
|
172
|
-
return NotReachable;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
NetworkStatus returnValue = NotReachable;
|
|
176
|
-
|
|
177
|
-
if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)
|
|
178
|
-
{
|
|
179
|
-
/*
|
|
180
|
-
If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi...
|
|
181
|
-
*/
|
|
182
|
-
returnValue = ReachableViaWiFi;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) ||
|
|
186
|
-
(flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0))
|
|
187
|
-
{
|
|
188
|
-
/*
|
|
189
|
-
... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs...
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0)
|
|
193
|
-
{
|
|
194
|
-
/*
|
|
195
|
-
... and no [user] intervention is needed...
|
|
196
|
-
*/
|
|
197
|
-
returnValue = ReachableViaWiFi;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN)
|
|
202
|
-
{
|
|
203
|
-
/*
|
|
204
|
-
... but WWAN connections are OK if the calling application is using the CFNetwork APIs.
|
|
205
|
-
*/
|
|
206
|
-
returnValue = ReachableViaWWAN;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return returnValue;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
- (BOOL)connectionRequired
|
|
214
|
-
{
|
|
215
|
-
NSAssert(_reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef");
|
|
216
|
-
SCNetworkReachabilityFlags flags;
|
|
217
|
-
|
|
218
|
-
if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags))
|
|
219
|
-
{
|
|
220
|
-
return (flags & kSCNetworkReachabilityFlagsConnectionRequired);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return NO;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
- (NetworkStatus)currentReachabilityStatus
|
|
228
|
-
{
|
|
229
|
-
NSAssert(_reachabilityRef != NULL, @"currentNetworkStatus called with NULL SCNetworkReachabilityRef");
|
|
230
|
-
NetworkStatus returnValue = NotReachable;
|
|
231
|
-
SCNetworkReachabilityFlags flags;
|
|
232
|
-
|
|
233
|
-
if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags))
|
|
234
|
-
{
|
|
235
|
-
returnValue = [self networkStatusForFlags:flags];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return returnValue;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
@end
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016 Apple Inc. All Rights Reserved.
|
|
3
|
+
See LICENSE.txt for this sample’s licensing information
|
|
4
|
+
|
|
5
|
+
Abstract:
|
|
6
|
+
Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#import <arpa/inet.h>
|
|
10
|
+
#import <ifaddrs.h>
|
|
11
|
+
#import <netdb.h>
|
|
12
|
+
#import <sys/socket.h>
|
|
13
|
+
#import <netinet/in.h>
|
|
14
|
+
|
|
15
|
+
#import <CoreFoundation/CoreFoundation.h>
|
|
16
|
+
|
|
17
|
+
#import "InternetConnection.h"
|
|
18
|
+
|
|
19
|
+
#pragma mark IPv6 Support
|
|
20
|
+
//Reachability fully support IPv6. For full details, see ReadMe.md.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotification";
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#pragma mark - Supporting functions
|
|
27
|
+
|
|
28
|
+
#define kShouldPrintReachabilityFlags 1
|
|
29
|
+
|
|
30
|
+
static void PrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment)
|
|
31
|
+
{
|
|
32
|
+
#if kShouldPrintReachabilityFlags
|
|
33
|
+
|
|
34
|
+
/* NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n",
|
|
35
|
+
(flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-',
|
|
36
|
+
(flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-',
|
|
37
|
+
|
|
38
|
+
(flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-',
|
|
39
|
+
(flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-',
|
|
40
|
+
(flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-',
|
|
41
|
+
(flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-',
|
|
42
|
+
(flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-',
|
|
43
|
+
(flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-',
|
|
44
|
+
(flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-',
|
|
45
|
+
comment
|
|
46
|
+
);*/
|
|
47
|
+
#endif
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info)
|
|
52
|
+
{
|
|
53
|
+
#pragma unused (target, flags)
|
|
54
|
+
NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback");
|
|
55
|
+
NSCAssert([(__bridge NSObject*) info isKindOfClass: [InternetConnection class]], @"info was wrong class in ReachabilityCallback");
|
|
56
|
+
|
|
57
|
+
InternetConnection* noteObject = (__bridge InternetConnection *)info;
|
|
58
|
+
// Post a notification to notify the client that the network reachability changed.
|
|
59
|
+
[[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#pragma mark - Reachability implementation
|
|
64
|
+
|
|
65
|
+
@implementation InternetConnection
|
|
66
|
+
{
|
|
67
|
+
SCNetworkReachabilityRef _reachabilityRef;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
+ (instancetype)reachabilityWithHostName:(NSString *)hostName
|
|
71
|
+
{
|
|
72
|
+
InternetConnection* returnValue = NULL;
|
|
73
|
+
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]);
|
|
74
|
+
if (reachability != NULL)
|
|
75
|
+
{
|
|
76
|
+
returnValue= [[self alloc] init];
|
|
77
|
+
if (returnValue != NULL)
|
|
78
|
+
{
|
|
79
|
+
returnValue->_reachabilityRef = reachability;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
CFRelease(reachability);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return returnValue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
+ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress
|
|
90
|
+
{
|
|
91
|
+
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, hostAddress);
|
|
92
|
+
|
|
93
|
+
InternetConnection* returnValue = NULL;
|
|
94
|
+
|
|
95
|
+
if (reachability != NULL)
|
|
96
|
+
{
|
|
97
|
+
returnValue = [[self alloc] init];
|
|
98
|
+
if (returnValue != NULL)
|
|
99
|
+
{
|
|
100
|
+
returnValue->_reachabilityRef = reachability;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
CFRelease(reachability);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return returnValue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
+ (instancetype)reachabilityForInternetConnection
|
|
111
|
+
{
|
|
112
|
+
struct sockaddr_in zeroAddress;
|
|
113
|
+
bzero(&zeroAddress, sizeof(zeroAddress));
|
|
114
|
+
zeroAddress.sin_len = sizeof(zeroAddress);
|
|
115
|
+
zeroAddress.sin_family = AF_INET;
|
|
116
|
+
|
|
117
|
+
return [self reachabilityWithAddress: (const struct sockaddr *) &zeroAddress];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#pragma mark reachabilityForLocalWiFi
|
|
121
|
+
//reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information.
|
|
122
|
+
//+ (instancetype)reachabilityForLocalWiFi
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
#pragma mark - Start and stop notifier
|
|
127
|
+
|
|
128
|
+
- (BOOL)startNotifier
|
|
129
|
+
{
|
|
130
|
+
BOOL returnValue = NO;
|
|
131
|
+
SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL};
|
|
132
|
+
|
|
133
|
+
if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context))
|
|
134
|
+
{
|
|
135
|
+
if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode))
|
|
136
|
+
{
|
|
137
|
+
returnValue = YES;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return returnValue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
- (void)stopNotifier
|
|
146
|
+
{
|
|
147
|
+
if (_reachabilityRef != NULL)
|
|
148
|
+
{
|
|
149
|
+
SCNetworkReachabilityUnscheduleFromRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
- (void)dealloc
|
|
155
|
+
{
|
|
156
|
+
[self stopNotifier];
|
|
157
|
+
if (_reachabilityRef != NULL)
|
|
158
|
+
{
|
|
159
|
+
CFRelease(_reachabilityRef);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
#pragma mark - Network Flag Handling
|
|
165
|
+
|
|
166
|
+
- (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags
|
|
167
|
+
{
|
|
168
|
+
PrintReachabilityFlags(flags, "networkStatusForFlags");
|
|
169
|
+
if ((flags & kSCNetworkReachabilityFlagsReachable) == 0)
|
|
170
|
+
{
|
|
171
|
+
// The target host is not reachable.
|
|
172
|
+
return NotReachable;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
NetworkStatus returnValue = NotReachable;
|
|
176
|
+
|
|
177
|
+
if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)
|
|
178
|
+
{
|
|
179
|
+
/*
|
|
180
|
+
If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi...
|
|
181
|
+
*/
|
|
182
|
+
returnValue = ReachableViaWiFi;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) ||
|
|
186
|
+
(flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0))
|
|
187
|
+
{
|
|
188
|
+
/*
|
|
189
|
+
... and the connection is on-demand (or on-traffic) if the calling application is using the CFSocketStream or higher APIs...
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0)
|
|
193
|
+
{
|
|
194
|
+
/*
|
|
195
|
+
... and no [user] intervention is needed...
|
|
196
|
+
*/
|
|
197
|
+
returnValue = ReachableViaWiFi;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN)
|
|
202
|
+
{
|
|
203
|
+
/*
|
|
204
|
+
... but WWAN connections are OK if the calling application is using the CFNetwork APIs.
|
|
205
|
+
*/
|
|
206
|
+
returnValue = ReachableViaWWAN;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return returnValue;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
- (BOOL)connectionRequired
|
|
214
|
+
{
|
|
215
|
+
NSAssert(_reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef");
|
|
216
|
+
SCNetworkReachabilityFlags flags;
|
|
217
|
+
|
|
218
|
+
if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags))
|
|
219
|
+
{
|
|
220
|
+
return (flags & kSCNetworkReachabilityFlagsConnectionRequired);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return NO;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
- (NetworkStatus)currentReachabilityStatus
|
|
228
|
+
{
|
|
229
|
+
NSAssert(_reachabilityRef != NULL, @"currentNetworkStatus called with NULL SCNetworkReachabilityRef");
|
|
230
|
+
NetworkStatus returnValue = NotReachable;
|
|
231
|
+
SCNetworkReachabilityFlags flags;
|
|
232
|
+
|
|
233
|
+
if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags))
|
|
234
|
+
{
|
|
235
|
+
returnValue = [self networkStatusForFlags:flags];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return returnValue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@end
|