Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

iOS console : reachability

William Balcaenf6c96226179b
diff --git a/console/iOS/console.xcodeproj/project.pbxproj b/console/iOS/console.xcodeproj/project.pbxproj
index 0c7056584..e3f75a4a3 100644
--- a/console/iOS/console.xcodeproj/project.pbxproj
+++ b/console/iOS/console.xcodeproj/project.pbxproj
@@ -19,6 +19,7 @@
FAA226B81E71563F009A8FEC /* TokenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA226B71E71563F009A8FEC /* TokenManager.swift */; };
FAA226BA1E715ED6009A8FEC /* TokenManagerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FAA226B91E715ED6009A8FEC /* TokenManagerView.xib */; };
FAA226BC1E7163D9009A8FEC /* TokenManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA226BB1E7163D9009A8FEC /* TokenManagerViewController.swift */; };
+ FABC54E81E7AEBD300B7B718 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = FABC54E71E7AEBD300B7B718 /* Reachability.m */; };
FAFF2E2D1E7A95120076BDE3 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAFF2E2C1E7A95120076BDE3 /* NotificationService.swift */; };
FAFF2E311E7A95120076BDE3 /* NotificationExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = FAFF2E2A1E7A95120076BDE3 /* NotificationExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
@@ -66,6 +67,9 @@
FAA226B91E715ED6009A8FEC /* TokenManagerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TokenManagerView.xib; sourceTree = "<group>"; };
FAA226BB1E7163D9009A8FEC /* TokenManagerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenManagerViewController.swift; sourceTree = "<group>"; };
FAAFD0B41E77EB6E00F01155 /* console.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = console.entitlements; sourceTree = "<group>"; };
+ FABC54E51E7AEBD200B7B718 /* console-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "console-Bridging-Header.h"; sourceTree = "<group>"; };
+ FABC54E61E7AEBD300B7B718 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
+ FABC54E71E7AEBD300B7B718 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
FAFF2E2A1E7A95120076BDE3 /* NotificationExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
FAFF2E2C1E7A95120076BDE3 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
FAFF2E2E1E7A95120076BDE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -151,9 +155,12 @@
FA2D48291E55D9F600C95665 /* utils */ = {
isa = PBXGroup;
children = (
+ FABC54E61E7AEBD300B7B718 /* Reachability.h */,
+ FABC54E71E7AEBD300B7B718 /* Reachability.m */,
FAA226B71E71563F009A8FEC /* TokenManager.swift */,
FAA226B91E715ED6009A8FEC /* TokenManagerView.xib */,
FAA226BB1E7163D9009A8FEC /* TokenManagerViewController.swift */,
+ FABC54E51E7AEBD200B7B718 /* console-Bridging-Header.h */,
);
name = utils;
sourceTree = "<group>";
@@ -344,6 +351,7 @@
FAA226BC1E7163D9009A8FEC /* TokenManagerViewController.swift in Sources */,
FA2D48311E560B7500C95665 /* Constants.swift in Sources */,
FA1D73E41E53374E00F6240A /* ViewController.swift in Sources */,
+ FABC54E81E7AEBD300B7B718 /* Reachability.m in Sources */,
FAA226B81E71563F009A8FEC /* TokenManager.swift in Sources */,
FA1D73F61E53392F00F6240A /* ORViewController.swift in Sources */,
FA1D73E21E53374E00F6240A /* AppDelegate.swift in Sources */,
@@ -488,6 +496,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = console/console.entitlements;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = console/Info.plist;
@@ -495,6 +504,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.openremote.console;
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_OBJC_BRIDGING_HEADER = "console/console-Bridging-Header.h";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
@@ -505,6 +516,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = console/console.entitlements;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = console/Info.plist;
@@ -512,6 +524,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.openremote.console;
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_OBJC_BRIDGING_HEADER = "console/console-Bridging-Header.h";
SWIFT_VERSION = 3.0;
};
name = Release;
diff --git a/console/iOS/console/AppDelegate.swift b/console/iOS/console/AppDelegate.swift
index d811fd7ae..877cc6490 100644
--- a/console/iOS/console/AppDelegate.swift
+++ b/console/iOS/console/AppDelegate.swift
@@ -11,13 +11,17 @@ import AppAuth
import UserNotifications
import Firebase
+
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
var currentAuthorizationFlow : OIDAuthorizationFlowSession?
let gcmMessageIDKey = "gcm.message_id"
- var isGrantedNotificationAccess:Bool = false
+ var reachabilityAlert : UIAlertController?
+ var reachabilityAlertShown = false
+ let internetReachability = Reachability.forInternetConnection()
+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
setActions()
@@ -34,31 +38,43 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
application.registerForRemoteNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)
-
+ NotificationCenter.default.addObserver(self,
+ selector: #selector(self.reachabilityChanged(note:)),
+ name: NSNotification.Name.reachabilityChanged,
+ object: internetReachability)
+ internetReachability?.startNotifier()
+ self.updateReachabilityStatus(reachability: internetReachability!)
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
+ internetReachability?.stopNotifier()
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+ internetReachability?.stopNotifier()
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
+ internetReachability?.startNotifier()
+ self.updateReachabilityStatus(reachability: internetReachability!)
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
connectToFcm()
+ internetReachability?.startNotifier()
+ self.updateReachabilityStatus(reachability: internetReachability!)
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+ internetReachability?.stopNotifier()
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
@@ -126,6 +142,44 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
connectToFcm()
}
+ func reachabilityChanged(note: NSNotification) {
+ if let reachability = note.object as? Reachability {
+ updateReachabilityStatus(reachability: reachability)
+ }
+ }
+
+ private func updateReachabilityStatus(reachability: Reachability) {
+ if reachability.currentReachabilityStatus() == NetworkStatus.NotReachable {
+ if (!reachabilityAlertShown) {
+ let topWindow = UIWindow(frame: UIScreen.main.bounds)
+ topWindow.rootViewController = UIViewController()
+ topWindow.windowLevel = UIWindowLevelAlert + 1
+
+ reachabilityAlert = UIAlertController(title: "Network Error", message: "Your device seems to be offline", preferredStyle: .alert)
+ let reachabilityRetryAction = UIAlertAction(title: "Retry", style: .default, handler: { (action) in
+ self.reachabilityAlertShown = false
+ self.updateReachabilityStatus(reachability: self.internetReachability!)
+ topWindow.isHidden = true
+ })
+ let reachabilityCancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) in
+ self.reachabilityAlertShown = false
+ self.reachabilityAlert?.dismiss(animated: true, completion: nil)
+ topWindow.isHidden = true
+ })
+ reachabilityAlert?.addAction(reachabilityRetryAction)
+ reachabilityAlert?.addAction(reachabilityCancelAction)
+ topWindow.makeKeyAndVisible()
+ topWindow.rootViewController?.present(reachabilityAlert!, animated: true, completion: nil)
+ reachabilityAlertShown = true
+ }
+ } else {
+ if (reachabilityAlertShown) {
+ reachabilityAlert?.dismiss(animated: true, completion: nil)
+ reachabilityAlertShown = false
+ }
+ }
+
+ }
}
@@ -150,6 +204,7 @@ func setActions() {
}
+
extension AppDelegate : FIRMessagingDelegate {
// Receive data message on iOS 10 devices while app is in the foreground.
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
diff --git a/console/iOS/console/Base.lproj/Main.storyboard b/console/iOS/console/Base.lproj/Main.storyboard
index 7264c24db..414b38524 100644
--- a/console/iOS/console/Base.lproj/Main.storyboard
+++ b/console/iOS/console/Base.lproj/Main.storyboard
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1212" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="6Y8-7o-wPy">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1217" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="6Y8-7o-wPy">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
@@ -24,7 +24,7 @@
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="umH-SD-HTu">
<rect key="frame" x="164" y="99" width="46" height="30"/>
<constraints>
- <constraint firstAttribute="width" constant="46" id="xRk-iq-U3F"/>
+ <constraint firstAttribute="width" constant="46" id="1xH-3I-upo"/>
</constraints>
<state key="normal" title="Login"/>
<connections>
@@ -34,8 +34,8 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
- <constraint firstItem="umH-SD-HTu" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="XBJ-fC-BR7"/>
- <constraint firstItem="umH-SD-HTu" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="35" id="lgG-Rh-Tmc"/>
+ <constraint firstItem="umH-SD-HTu" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="35" id="3F6-5u-bL5"/>
+ <constraint firstItem="umH-SD-HTu" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="se7-gs-Skk"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="Mok-S7-Wng"/>
diff --git a/console/iOS/console/Constants.swift b/console/iOS/console/Constants.swift
index a518ffaa7..c7e45fde2 100644
--- a/console/iOS/console/Constants.swift
+++ b/console/iOS/console/Constants.swift
@@ -8,7 +8,7 @@
import Foundation
-struct Server {
+enum Server {
static let hostURL = "192.168.99.100"
static let port = "8080"
static let initialPath = String(format:"console/%@/index.html",Server.realm)
@@ -16,20 +16,27 @@ struct Server {
static let apiTestResource = String(format:"http://%@:%@/%@/asset",Server.hostURL,Server.port,Server.realm)
}
-struct Client {
+enum Client {
static let clientId = "openremote"
}
-struct DefaultsKey {
+enum DefaultsKey {
static let offlineToken = "offlineToken"
static let refreshToken = "refreshToken"
static let idToken = "idToken"
}
-struct NotificationsNames {
+enum NotificationsNames {
static let isAuthenticated = "isAuthenticated"
}
-struct AppGroup {
+enum AppGroup {
static let entitlement = "group.org.openremote.console"
}
+
+enum Notifications {
+ static let needsReachabilityCheck = Notification.Name("NeedsReachabilityCheck")
+ static let fullScreenShown = Notification.Name("fullScreenShown")
+ static let fullScreenHidden = Notification.Name("fullScreenHidden")
+ static let idleTimerFired = Notification.Name("idleTimerFired")
+}
diff --git a/console/iOS/console/ORViewController.swift b/console/iOS/console/ORViewController.swift
index fe45f75ba..ae3056127 100644
--- a/console/iOS/console/ORViewController.swift
+++ b/console/iOS/console/ORViewController.swift
@@ -42,9 +42,9 @@ class ORViewcontroller : UIViewController, URLSessionDelegate, WKScriptMessageHa
myWebView?.navigationDelegate = self;
view.addSubview(myWebView!)
- self.apiCall()
+ //self.apiCall()
- //self.login()
+ self.login()
}
diff --git a/console/iOS/console/Reachability.h b/console/iOS/console/Reachability.h
new file mode 100644
index 000000000..812e268f3
--- /dev/null
+++ b/console/iOS/console/Reachability.h
@@ -0,0 +1,66 @@
+/*
+ Copyright (C) 2016 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
+ */
+
+#import <Foundation/Foundation.h>
+#import <SystemConfiguration/SystemConfiguration.h>
+#import <netinet/in.h>
+
+
+typedef NS_ENUM(NSUInteger, NetworkStatus) {
+ NotReachable = 0,
+ ReachableViaWiFi = 1,
+ ReachableViaWWAN = 2
+};
+
+#pragma mark IPv6 Support
+//Reachability fully support IPv6. For full details, see ReadMe.md.
+
+
+extern NSString *kReachabilityChangedNotification;
+
+
+@interface Reachability : NSObject
+
+/*!
+ * Use to check the reachability of a given host name.
+ */
++ (instancetype)reachabilityWithHostName:(NSString *)hostName;
+
+/*!
+ * Use to check the reachability of a given IP address.
+ */
++ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress;
+
+/*!
+ * Checks whether the default route is available. Should be used by applications that do not connect to a particular host.
+ */
++ (instancetype)reachabilityForInternetConnection;
+
+
+#pragma mark reachabilityForLocalWiFi
+//reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information.
+//+ (instancetype)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;
+
++ (BOOL)isConnectedToNetwork;
+
+@end
+
+
diff --git a/console/iOS/console/Reachability.m b/console/iOS/console/Reachability.m
new file mode 100644
index 000000000..0c96c4e3b
--- /dev/null
+++ b/console/iOS/console/Reachability.m
@@ -0,0 +1,244 @@
+/*
+ Copyright (C) 2016 Apple Inc. All Rights Reserved.
+ See LICENSE.txt for this sample’s licensing information
+
+ Abstract:
+ Basic demonstration of how to use the SystemConfiguration Reachablity APIs.
+ */
+
+#import <arpa/inet.h>
+#import <ifaddrs.h>
+#import <netdb.h>
+#import <sys/socket.h>
+#import <netinet/in.h>
+
+#import <CoreFoundation/CoreFoundation.h>
+
+#import "Reachability.h"
+
+#pragma mark IPv6 Support
+//Reachability fully support IPv6. For full details, see ReadMe.md.
+
+
+NSString *kReachabilityChangedNotification = @"kNetworkReachabilityChangedNotification";
+
+
+#pragma mark - Supporting functions
+
+#define kShouldPrintReachabilityFlags 0
+
+static void PrintReachabilityFlags(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
+}
+
+
+static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info)
+{
+ Reachability* noteObject = (__bridge Reachability *)info;
+ // Post a notification to notify the client that the network reachability changed.
+ [[NSNotificationCenter defaultCenter] postNotificationName: kReachabilityChangedNotification object: noteObject];
+}
+
+
+#pragma mark - Reachability implementation
+
+@implementation Reachability
+{
+ SCNetworkReachabilityRef _reachabilityRef;
+}
+
++ (instancetype)reachabilityWithHostName:(NSString *)hostName
+{
+ Reachability* returnValue = NULL;
+ SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]);
+ if (reachability != NULL)
+ {
+ returnValue= [[self alloc] init];
+ if (returnValue != NULL)
+ {
+ returnValue->_reachabilityRef = reachability;
+ }
+ else {
+ CFRelease(reachability);
+ }
+ }
+ return returnValue;
+}
+
+
++ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress
+{
+ SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, hostAddress);
+
+ Reachability* returnValue = NULL;
+
+ if (reachability != NULL)
+ {
+ returnValue = [[self alloc] init];
+ if (returnValue != NULL)
+ {
+ returnValue->_reachabilityRef = reachability;
+ }
+ else {
+ CFRelease(reachability);
+ }
+ }
+ return returnValue;
+}
+
+
++ (instancetype)reachabilityForInternetConnection
+{
+ struct sockaddr_in zeroAddress;
+ bzero(&zeroAddress, sizeof(zeroAddress));
+ zeroAddress.sin_len = sizeof(zeroAddress);
+ zeroAddress.sin_family = AF_INET;
+
+ return [self reachabilityWithAddress: (const struct sockaddr *) &zeroAddress];
+}
+
+#pragma mark reachabilityForLocalWiFi
+//reachabilityForLocalWiFi has been removed from the sample. See ReadMe.md for more information.
+//+ (instancetype)reachabilityForLocalWiFi
+
+
+
+#pragma mark - Start and stop notifier
+
+- (BOOL)startNotifier
+{
+ BOOL returnValue = NO;
+ SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL};
+
+ if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context))
+ {
+ if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode))
+ {
+ returnValue = YES;
+ }
+ }
+
+ return returnValue;
+}
+
+
+- (void)stopNotifier
+{
+ if (_reachabilityRef != NULL)
+ {
+ SCNetworkReachabilityUnscheduleFromRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+ }
+}
+
+
+- (void)dealloc
+{
+ [self stopNotifier];
+ if (_reachabilityRef != NULL)
+ {
+ CFRelease(_reachabilityRef);
+ }
+}
+
+
+#pragma mark - Network Flag Handling
+
+- (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags
+{
+ PrintReachabilityFlags(flags, "networkStatusForFlags");
+ if ((flags & kSCNetworkReachabilityFlagsReachable) == 0)
+ {
+ // The target host is not reachable.
+ return NotReachable;
+ }
+
+ NetworkStatus returnValue = NotReachable;
+
+ if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0)
+ {
+ /*
+ If the target host is reachable and no connection is required then we'll assume (for now) that you're on Wi-Fi...
+ */
+ returnValue = 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...
+ */
+ returnValue = ReachableViaWiFi;
+ }
+ }
+
+ if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN)
+ {
+ /*
+ ... but WWAN connections are OK if the calling application is using the CFNetwork APIs.
+ */
+ returnValue = ReachableViaWWAN;
+ }
+
+ return returnValue;
+}
+
+- (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 SCNetworkReachabilityRef");
+ NetworkStatus returnValue = NotReachable;
+ SCNetworkReachabilityFlags flags;
+
+ if (SCNetworkReachabilityGetFlags(_reachabilityRef, &flags))
+ {
+ returnValue = [self networkStatusForFlags:flags];
+ }
+
+ return returnValue;
+}
+
++ (BOOL)isConnectedToNetwork
+{
+ NetworkStatus status = [Reachability reachabilityForInternetConnection].currentReachabilityStatus;
+ if (status != NotReachable) {
+ return true;
+ }
+ return false;
+}
+
+@end
diff --git a/console/iOS/console/console-Bridging-Header.h b/console/iOS/console/console-Bridging-Header.h
new file mode 100644
index 000000000..5c344b317
--- /dev/null
+++ b/console/iOS/console/console-Bridging-Header.h
@@ -0,0 +1,5 @@
+//
+// Use this file to import your target's public headers that you would like to expose to Swift.
+//
+
+#import "Reachability.h"