Repository: cordova-osx Updated Branches: refs/heads/master 2b7076ae8 -> ea9a45b86
CB-10084 OSX: (re)move connectivity in favour of cordova-plugin-network-information Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/ea9a45b8 Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/ea9a45b8 Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/ea9a45b8 Branch: refs/heads/master Commit: ea9a45b86af25edb515aabc84ad4ba7a87a5d15f Parents: 2b7076a Author: Tobias Bocanegra <tri...@adobe.com> Authored: Wed Nov 25 17:18:53 2015 -0800 Committer: Tobias Bocanegra <tri...@adobe.com> Committed: Wed Nov 25 17:18:53 2015 -0800 ---------------------------------------------------------------------- CordovaLib/CordovaLib.xcodeproj/project.pbxproj | 16 -- .../CordovaLib/Classes/Commands/CDVConnection.h | 34 --- .../CordovaLib/Classes/Commands/CDVConnection.m | 125 --------- .../Classes/Commands/CDVReachability.h | 85 ------ .../Classes/Commands/CDVReachability.m | 261 ------------------- 5 files changed, 521 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/ea9a45b8/CordovaLib/CordovaLib.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj index 1caba1c..4392997 100644 --- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj +++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj @@ -23,8 +23,6 @@ 70BD67A318FFA12D00A1EFCF /* CDVCommandQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD677C18FFA12D00A1EFCF /* CDVCommandQueue.m */; }; 70BD67A418FFA12D00A1EFCF /* CDVConfigParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD677D18FFA12D00A1EFCF /* CDVConfigParser.h */; settings = {ATTRIBUTES = (Public, ); }; }; 70BD67A518FFA12D00A1EFCF /* CDVConfigParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD677E18FFA12D00A1EFCF /* CDVConfigParser.m */; }; - 70BD67A618FFA12D00A1EFCF /* CDVConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD677F18FFA12D00A1EFCF /* CDVConnection.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 70BD67A718FFA12D00A1EFCF /* CDVConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD678018FFA12D00A1EFCF /* CDVConnection.m */; }; 70BD67A818FFA12D00A1EFCF /* CDVConsole.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD678118FFA12D00A1EFCF /* CDVConsole.h */; settings = {ATTRIBUTES = (Public, ); }; }; 70BD67A918FFA12D00A1EFCF /* CDVConsole.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD678218FFA12D00A1EFCF /* CDVConsole.m */; }; 70BD67AA18FFA12D00A1EFCF /* CDVDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD678318FFA12D00A1EFCF /* CDVDebug.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -38,8 +36,6 @@ 70BD67B218FFA12D00A1EFCF /* CDVPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD678B18FFA12D00A1EFCF /* CDVPlugin.m */; }; 70BD67B318FFA12D00A1EFCF /* CDVPluginResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD678C18FFA12D00A1EFCF /* CDVPluginResult.h */; settings = {ATTRIBUTES = (Public, ); }; }; 70BD67B418FFA12D00A1EFCF /* CDVPluginResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD678D18FFA12D00A1EFCF /* CDVPluginResult.m */; }; - 70BD67B518FFA12D00A1EFCF /* CDVReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD678E18FFA12D00A1EFCF /* CDVReachability.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 70BD67B618FFA12D00A1EFCF /* CDVReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD678F18FFA12D00A1EFCF /* CDVReachability.m */; }; 70BD67B718FFA12D00A1EFCF /* NSData+Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD679118FFA12D00A1EFCF /* NSData+Base64.h */; settings = {ATTRIBUTES = (Public, ); }; }; 70BD67B818FFA12D00A1EFCF /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD679218FFA12D00A1EFCF /* NSData+Base64.m */; }; 70BD67B918FFA12D00A1EFCF /* NSWindow+Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD679318FFA12D00A1EFCF /* NSWindow+Utils.h */; }; @@ -81,8 +77,6 @@ 70BD677C18FFA12D00A1EFCF /* CDVCommandQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVCommandQueue.m; sourceTree = "<group>"; }; 70BD677D18FFA12D00A1EFCF /* CDVConfigParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVConfigParser.h; sourceTree = "<group>"; }; 70BD677E18FFA12D00A1EFCF /* CDVConfigParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVConfigParser.m; sourceTree = "<group>"; }; - 70BD677F18FFA12D00A1EFCF /* CDVConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVConnection.h; sourceTree = "<group>"; }; - 70BD678018FFA12D00A1EFCF /* CDVConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVConnection.m; sourceTree = "<group>"; }; 70BD678118FFA12D00A1EFCF /* CDVConsole.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVConsole.h; sourceTree = "<group>"; }; 70BD678218FFA12D00A1EFCF /* CDVConsole.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVConsole.m; sourceTree = "<group>"; }; 70BD678318FFA12D00A1EFCF /* CDVDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVDebug.h; sourceTree = "<group>"; }; @@ -96,8 +90,6 @@ 70BD678B18FFA12D00A1EFCF /* CDVPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVPlugin.m; sourceTree = "<group>"; }; 70BD678C18FFA12D00A1EFCF /* CDVPluginResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVPluginResult.h; sourceTree = "<group>"; }; 70BD678D18FFA12D00A1EFCF /* CDVPluginResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVPluginResult.m; sourceTree = "<group>"; }; - 70BD678E18FFA12D00A1EFCF /* CDVReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVReachability.h; sourceTree = "<group>"; }; - 70BD678F18FFA12D00A1EFCF /* CDVReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVReachability.m; sourceTree = "<group>"; }; 70BD679118FFA12D00A1EFCF /* NSData+Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+Base64.h"; sourceTree = "<group>"; }; 70BD679218FFA12D00A1EFCF /* NSData+Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Base64.m"; sourceTree = "<group>"; }; 70BD679318FFA12D00A1EFCF /* NSWindow+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSWindow+Utils.h"; sourceTree = "<group>"; }; @@ -219,8 +211,6 @@ 70BD677C18FFA12D00A1EFCF /* CDVCommandQueue.m */, 70BD677D18FFA12D00A1EFCF /* CDVConfigParser.h */, 70BD677E18FFA12D00A1EFCF /* CDVConfigParser.m */, - 70BD677F18FFA12D00A1EFCF /* CDVConnection.h */, - 70BD678018FFA12D00A1EFCF /* CDVConnection.m */, 70BD678118FFA12D00A1EFCF /* CDVConsole.h */, 70BD678218FFA12D00A1EFCF /* CDVConsole.m */, 70BD678318FFA12D00A1EFCF /* CDVDebug.h */, @@ -234,8 +224,6 @@ 70BD678B18FFA12D00A1EFCF /* CDVPlugin.m */, 70BD678C18FFA12D00A1EFCF /* CDVPluginResult.h */, 70BD678D18FFA12D00A1EFCF /* CDVPluginResult.m */, - 70BD678E18FFA12D00A1EFCF /* CDVReachability.h */, - 70BD678F18FFA12D00A1EFCF /* CDVReachability.m */, CC6A0DB9905DAB3A94C6BCC8 /* CDVWindowSizeCommand.m */, CC6A03B1971BACCB9183AEFE /* CDVWindowSizeCommand.h */, CC6A08BE679E9B2A17CB995E /* CDVCursorMonitorService.h */, @@ -269,7 +257,6 @@ 70BD67A218FFA12D00A1EFCF /* CDVCommandQueue.h in Headers */, 70BD67A418FFA12D00A1EFCF /* CDVConfigParser.h in Headers */, 70BD679D18FFA12D00A1EFCF /* CDV.h in Headers */, - 70BD67B518FFA12D00A1EFCF /* CDVReachability.h in Headers */, 70BD67AD18FFA12D00A1EFCF /* CDVInvokedUrlCommand.h in Headers */, 70BD679718FFA12D00A1EFCF /* CDVBridge.h in Headers */, 70BD67AB18FFA12D00A1EFCF /* CDVDevice.h in Headers */, @@ -284,7 +271,6 @@ 70BD67BB18FFA12D00A1EFCF /* ShellUtils.h in Headers */, 70BD67B118FFA12D00A1EFCF /* CDVPlugin.h in Headers */, 70BD67B318FFA12D00A1EFCF /* CDVPluginResult.h in Headers */, - 70BD67A618FFA12D00A1EFCF /* CDVConnection.h in Headers */, 70BD67A018FFA12D00A1EFCF /* CDVCommandDelegateImpl.h in Headers */, 70BD67B918FFA12D00A1EFCF /* NSWindow+Utils.h in Headers */, CC6A01B9AD6ECF2D913FF418 /* CDVWindowSizeCommand.h in Headers */, @@ -354,7 +340,6 @@ 70BD67A318FFA12D00A1EFCF /* CDVCommandQueue.m in Sources */, 70BD67B818FFA12D00A1EFCF /* NSData+Base64.m in Sources */, 70BD67AC18FFA12D00A1EFCF /* CDVDevice.m in Sources */, - 70BD67B618FFA12D00A1EFCF /* CDVReachability.m in Sources */, 70BD679C18FFA12D00A1EFCF /* CDVWebViewDelegate.m in Sources */, 70BD679818FFA12D00A1EFCF /* CDVBridge.m in Sources */, 70BD67BC18FFA12D00A1EFCF /* ShellUtils.m in Sources */, @@ -363,7 +348,6 @@ 70BD67B218FFA12D00A1EFCF /* CDVPlugin.m in Sources */, 70BD67BA18FFA12D00A1EFCF /* NSWindow+Utils.m in Sources */, 70BD67B418FFA12D00A1EFCF /* CDVPluginResult.m in Sources */, - 70BD67A718FFA12D00A1EFCF /* CDVConnection.m in Sources */, CC6A07EE3FA39E9ED21FC2AD /* CDVWindowSizeCommand.m in Sources */, CC6A0C2EAD9E57810677CE21 /* NSScreen+Utils.m in Sources */, CC6A03130738A1F299369195 /* CDVCursorMonitorService.m in Sources */, http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/ea9a45b8/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.h b/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.h deleted file mode 100644 index d3e8c5d..0000000 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import <Foundation/Foundation.h> -#import "CDVPlugin.h" -#import "CDVReachability.h" - -@interface CDVConnection : CDVPlugin { - NSString* type; - NSString* _callbackId; - - CDVReachability* internetReach; -} - -@property (copy) NSString* connectionType; -@property (strong) CDVReachability* internetReach; - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/ea9a45b8/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.m b/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.m deleted file mode 100644 index 61030d3..0000000 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVConnection.m +++ /dev/null @@ -1,125 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "CDVConnection.h" -#import "CDVReachability.h" - -@interface CDVConnection (PrivateMethods) -- (void)updateOnlineStatus; -- (void)sendPluginResult; -@end - -@implementation CDVConnection - -@synthesize connectionType, internetReach; - -- (void)getConnectionInfo:(CDVInvokedUrlCommand*)command -{ - _callbackId = command.callbackId; - [self sendPluginResult]; -} - -- (void)sendPluginResult -{ - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:self.connectionType]; - - [result setKeepCallbackAsBool:YES]; - [self.commandDelegate sendPluginResult:result callbackId:_callbackId]; -} - -- (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability -{ - NetworkStatus networkStatus = [reachability currentReachabilityStatus]; - - switch (networkStatus) { - case NotReachable: - return @"none"; - - case ReachableViaWWAN: - return @"2g"; // no generic default, so we use the lowest common denominator - - case ReachableViaWiFi: - return @"wifi"; - - default: - return @"unknown"; - } -} - -- (BOOL)isCellularConnection:(NSString*)theConnectionType -{ - return [theConnectionType isEqualToString:@"2g"] || - [theConnectionType isEqualToString:@"3g"] || - [theConnectionType isEqualToString:@"4g"]; -} - -- (void)updateReachability:(CDVReachability*)reachability -{ - if (reachability) { - // check whether the connection type has changed - NSString* newConnectionType = [self w3cConnectionTypeFor:reachability]; - if ([newConnectionType isEqualToString:self.connectionType]) { // the same as before, remove dupes - return; - } else { - self.connectionType = [self w3cConnectionTypeFor:reachability]; - } - } - [self sendPluginResult]; -} - -- (void)updateConnectionType:(NSNotification*)note -{ - CDVReachability* curReach = [note object]; - - if ((curReach != nil) && [curReach isKindOfClass:[CDVReachability class]]) { - [self updateReachability:curReach]; - } -} - -- (void)onPause -{ - [self.internetReach stopNotifier]; -} - -- (void)onResume -{ - [self.internetReach startNotifier]; - [self updateReachability:self.internetReach]; -} - -- (CDVPlugin*)initWithWebView:(WebView*)theWebView -{ - self = [super initWithWebView:theWebView]; - if (self) { - self.connectionType = @"none"; - self.internetReach = [CDVReachability reachabilityForInternetConnection]; - self.connectionType = [self w3cConnectionTypeFor:self.internetReach]; - [self.internetReach startNotifier]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConnectionType:) - name:kReachabilityChangedNotification object:nil]; -// TODO: -// if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) { -// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil]; -// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil]; -// } - } - return self; -} - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/ea9a45b8/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.h b/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.h deleted file mode 100644 index 01a95c3..0000000 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - - File: Reachability.h - Abstract: Basic demonstration of how to use the SystemConfiguration Reachability APIs. - Version: 2.2 - - Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. - ("Apple") in consideration of your agreement to the following terms, and your - use, installation, modification or redistribution of this Apple software - constitutes acceptance of these terms. If you do not agree with these terms, - please do not use, install, modify or redistribute this Apple software. - - In consideration of your agreement to abide by the following terms, and subject - to these terms, Apple grants you a personal, non-exclusive license, under - Apple's copyrights in this original Apple software (the "Apple Software"), to - use, reproduce, modify and redistribute the Apple Software, with or without - modifications, in source and/or binary forms; provided that if you redistribute - the Apple Software in its entirety and without modifications, you must retain - this notice and the following text and disclaimers in all such redistributions - of the Apple Software. - Neither the name, trademarks, service marks or logos of Apple Inc. may be used - to endorse or promote products derived from the Apple Software without specific - prior written permission from Apple. Except as expressly stated in this notice, - no other rights or licenses, express or implied, are granted by Apple herein, - including but not limited to any patent rights that may be infringed by your - derivative works or by other works in which the Apple Software may be - incorporated. - - The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO - WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED - WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN - COMBINATION WITH YOUR PRODUCTS. - - IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR - DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF - CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF - APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Copyright (C) 2010 Apple Inc. All Rights Reserved. - -*/ - -#import <Foundation/Foundation.h> -#import <SystemConfiguration/SystemConfiguration.h> -#import <netinet/in.h> - -typedef enum { - NotReachable = 0, - ReachableViaWWAN, // this value has been swapped with ReachableViaWiFi for Cordova backwards compat. reasons - ReachableViaWiFi // this value has been swapped with ReachableViaWWAN for Cordova backwards compat. reasons -} NetworkStatus; -#define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification" - -@interface CDVReachability : NSObject -{ - BOOL localWiFiRef; - SCNetworkReachabilityRef reachabilityRef; -} - -// reachabilityWithHostName- Use to check the reachability of a particular host name. -+ (CDVReachability*)reachabilityWithHostName:(NSString*)hostName; - -// reachabilityWithAddress- Use to check the reachability of a particular IP address. -+ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress; - -// reachabilityForInternetConnection- checks whether the default route is available. -// Should be used by applications that do not connect to a particular host -+ (CDVReachability*)reachabilityForInternetConnection; - -// reachabilityForLocalWiFi- checks whether a local wifi connection is available. -+ (CDVReachability*)reachabilityForLocalWiFi; - -// Start listening for reachability notifications on the current run loop -- (BOOL)startNotifier; -- (void)stopNotifier; - -- (NetworkStatus)currentReachabilityStatus; -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. -- (BOOL)connectionRequired; -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/ea9a45b8/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.m b/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.m deleted file mode 100644 index ed1afe7..0000000 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVReachability.m +++ /dev/null @@ -1,261 +0,0 @@ -/* - - File: Reachability.m - Abstract: Basic demonstration of how to use the SystemConfiguration Reachability APIs. - Version: 2.2 - - Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. - ("Apple") in consideration of your agreement to the following terms, and your - use, installation, modification or redistribution of this Apple software - constitutes acceptance of these terms. If you do not agree with these terms, - please do not use, install, modify or redistribute this Apple software. - - In consideration of your agreement to abide by the following terms, and subject - to these terms, Apple grants you a personal, non-exclusive license, under - Apple's copyrights in this original Apple software (the "Apple Software"), to - use, reproduce, modify and redistribute the Apple Software, with or without - modifications, in source and/or binary forms; provided that if you redistribute - the Apple Software in its entirety and without modifications, you must retain - this notice and the following text and disclaimers in all such redistributions - of the Apple Software. - Neither the name, trademarks, service marks or logos of Apple Inc. may be used - to endorse or promote products derived from the Apple Software without specific - prior written permission from Apple. Except as expressly stated in this notice, - no other rights or licenses, express or implied, are granted by Apple herein, - including but not limited to any patent rights that may be infringed by your - derivative works or by other works in which the Apple Software may be - incorporated. - - The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO - WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED - WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN - COMBINATION WITH YOUR PRODUCTS. - - IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR - DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF - CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF - APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Copyright (C) 2010 Apple Inc. All Rights Reserved. - -*/ - -#import <sys/socket.h> -#import <netinet/in.h> -#import <netinet6/in6.h> -#import <arpa/inet.h> -#import <ifaddrs.h> -#import <netdb.h> - -#import <CoreFoundation/CoreFoundation.h> - -#import "CDVReachability.h" - -#define kShouldPrintReachabilityFlags 0 - -static void CDVPrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment) -{ -#if kShouldPrintReachabilityFlags - NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n", - (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', - (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', - - (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', - (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', - (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', - (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-', - comment - ); -#endif -} - -@implementation CDVReachability - -static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) -{ -#pragma unused (target, flags) - // NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback"); - // NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); - - // Converted the asserts above to conditionals, with safe return from the function - if (info == NULL) { - NSLog(@"info was NULL in ReachabilityCallback"); - return; - } - - if (![(__bridge NSObject*) info isKindOfClass:[CDVReachability class]]) { - NSLog(@"info was wrong class in ReachabilityCallback"); - return; - } - - // We're on the main RunLoop, so an NSAutoreleasePool is not necessary, but is added defensively - // in case someon uses the Reachability object in a different thread. - @autoreleasepool { - CDVReachability* noteObject = (__bridge CDVReachability*)info; - // Post a notification to notify the client that the network reachability changed. - [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:noteObject]; - } -} - -- (BOOL)startNotifier -{ - BOOL retVal = NO; - SCNetworkReachabilityContext context = {0, (__bridge void*)(self), NULL, NULL, NULL}; - - if (SCNetworkReachabilitySetCallback(reachabilityRef, CDVReachabilityCallback, &context)) { - if (SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) { - retVal = YES; - } - } - return retVal; -} - -- (void)stopNotifier -{ - if (reachabilityRef != NULL) { - SCNetworkReachabilityUnscheduleFromRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - } -} - -- (void)dealloc -{ - [self stopNotifier]; - if (reachabilityRef != NULL) { - CFRelease(reachabilityRef); - } - -} - -+ (CDVReachability*)reachabilityWithHostName:(NSString*)hostName; -{ - CDVReachability* retVal = NULL; - SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); - if (reachability != NULL) { - retVal = [[self alloc] init]; - if (retVal != NULL) { - retVal->reachabilityRef = reachability; - retVal->localWiFiRef = NO; - } - } - return retVal; -} - -+ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress; -{ - SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress); - CDVReachability* retVal = NULL; - if (reachability != NULL) { - retVal = [[self alloc] init]; - if (retVal != NULL) { - retVal->reachabilityRef = reachability; - retVal->localWiFiRef = NO; - } - } - return retVal; -} - -+ (CDVReachability*)reachabilityForInternetConnection; -{ - struct sockaddr_in zeroAddress; - bzero(&zeroAddress, sizeof(zeroAddress)); - zeroAddress.sin_len = sizeof(zeroAddress); - zeroAddress.sin_family = AF_INET; - return [self reachabilityWithAddress:&zeroAddress]; -} - -+ (CDVReachability*)reachabilityForLocalWiFi; -{ - struct sockaddr_in localWifiAddress; - bzero(&localWifiAddress, sizeof(localWifiAddress)); - localWifiAddress.sin_len = sizeof(localWifiAddress); - localWifiAddress.sin_family = AF_INET; - // IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0 - localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); - CDVReachability* retVal = [self reachabilityWithAddress:&localWifiAddress]; - if (retVal != NULL) { - retVal->localWiFiRef = YES; - } - return retVal; -} - -#pragma mark Network Flag Handling - -- (NetworkStatus)localWiFiStatusForFlags:(SCNetworkReachabilityFlags)flags -{ - CDVPrintReachabilityFlags(flags, "localWiFiStatusForFlags"); - - BOOL retVal = NotReachable; - if ((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) { - retVal = ReachableViaWiFi; - } - return retVal; -} - -- (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags -{ - CDVPrintReachabilityFlags(flags, "networkStatusForFlags"); - if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) { - // if target host is not reachable - return NotReachable; - } - - BOOL retVal = NotReachable; - - if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) { - // if target host is reachable and no connection is required - // then we'll assume (for now) that your on Wi-Fi - retVal = ReachableViaWiFi; - } - - if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0) || - ((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0))) { - // ... and the connection is on-demand (or on-traffic) if the - // calling application is using the CFSocketStream or higher APIs - - if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) { - // ... and no [user] intervention is needed - retVal = ReachableViaWiFi; - } - } - - if ((flags & kSCNetworkReachabilityFlagsIsDirect) == kSCNetworkReachabilityFlagsIsDirect) { - // ... but WWAN connections are OK if the calling application - // is using the CFNetwork (CFSocketStream?) APIs. - retVal = ReachableViaWWAN; - } - return retVal; -} - -- (BOOL)connectionRequired; -{ - NSAssert(reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef"); - SCNetworkReachabilityFlags flags; - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) { - return flags & kSCNetworkReachabilityFlagsConnectionRequired; - } - return NO; -} - -- (NetworkStatus)currentReachabilityStatus -{ - NSAssert(reachabilityRef != NULL, @"currentNetworkStatus called with NULL reachabilityRef"); - NetworkStatus retVal = NotReachable; - SCNetworkReachabilityFlags flags; - if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) { - if (localWiFiRef) { - retVal = [self localWiFiStatusForFlags:flags]; - } else { - retVal = [self networkStatusForFlags:flags]; - } - } - return retVal; -} - -@end --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org