Explorar el Código

Update TV sample app

Ashley Mills hace 9 años
padre
commit
1bdb8c4f35

+ 3 - 0
Reachability.xcodeproj/project.pbxproj

@@ -426,6 +426,7 @@
 					};
 					};
 					57A45A001C197BE800384AE4 = {
 					57A45A001C197BE800384AE4 = {
 						CreatedOnToolsVersion = 7.1.1;
 						CreatedOnToolsVersion = 7.1.1;
+						LastSwiftMigration = 0800;
 					};
 					};
 					57A45A291C197F4800384AE4 = {
 					57A45A291C197F4800384AE4 = {
 						CreatedOnToolsVersion = 7.1.1;
 						CreatedOnToolsVersion = 7.1.1;
@@ -722,6 +723,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = swift.reachability.ReachabilityAppleTVSample;
 				PRODUCT_BUNDLE_IDENTIFIER = swift.reachability.ReachabilityAppleTVSample;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SDKROOT = appletvos;
 				SDKROOT = appletvos;
+				SWIFT_VERSION = 3.0;
 				TARGETED_DEVICE_FAMILY = 3;
 				TARGETED_DEVICE_FAMILY = 3;
 				TVOS_DEPLOYMENT_TARGET = 9.0;
 				TVOS_DEPLOYMENT_TARGET = 9.0;
 			};
 			};
@@ -740,6 +742,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SDKROOT = appletvos;
 				SDKROOT = appletvos;
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 3.0;
 				TARGETED_DEVICE_FAMILY = 3;
 				TARGETED_DEVICE_FAMILY = 3;
 				TVOS_DEPLOYMENT_TARGET = 9.0;
 				TVOS_DEPLOYMENT_TARGET = 9.0;
 			};
 			};

+ 2 - 28
ReachabilityAppleTVSample/AppDelegate.swift

@@ -12,35 +12,9 @@ import UIKit
 class AppDelegate: UIResponder, UIApplicationDelegate {
 class AppDelegate: UIResponder, UIApplicationDelegate {
 
 
     var window: UIWindow?
     var window: UIWindow?
-
-
-    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
-        // Override point for customization after application launch.
+    
+    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
         return true
         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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
-    }
-
-    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.
-    }
-
-    func applicationWillEnterForeground(application: UIApplication) {
-        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
-    }
-
-    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.
-    }
-
-    func applicationWillTerminate(application: UIApplication) {
-        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
-    }
-
-
 }
 }
 
 

+ 15 - 15
ReachabilityAppleTVSample/ViewController.swift

@@ -24,15 +24,15 @@ class ViewController: UIViewController {
         startNotifier()
         startNotifier()
         
         
         // After 5 seconds, stop and re-start reachability, this time using a hostname
         // After 5 seconds, stop and re-start reachability, this time using a hostname
-        let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(UInt64(5) * NSEC_PER_SEC))
-        dispatch_after(dispatchTime, dispatch_get_main_queue()) {
+        let dispatchTime = DispatchTime.now() + Double(Int64(UInt64(5) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)
+        DispatchQueue.main.asyncAfter(deadline: dispatchTime) {
             self.stopNotifier()
             self.stopNotifier()
             self.setupReachability(useHostName: true, useClosures: true)
             self.setupReachability(useHostName: true, useClosures: true)
             self.startNotifier()
             self.startNotifier()
         }
         }
     }
     }
     
     
-    func setupReachability(useHostName useHostName: Bool, useClosures: Bool) {
+    func setupReachability(useHostName: Bool, useClosures: Bool) {
         let hostName = "google.com"
         let hostName = "google.com"
         hostNameLabel.text = useHostName ? hostName : "No host name"
         hostNameLabel.text = useHostName ? hostName : "No host name"
         
         
@@ -42,7 +42,7 @@ class ViewController: UIViewController {
             let reachability = try useHostName ? Reachability(hostname: hostName) : Reachability.reachabilityForInternetConnection()
             let reachability = try useHostName ? Reachability(hostname: hostName) : Reachability.reachabilityForInternetConnection()
             self.reachability = reachability
             self.reachability = reachability
         } catch ReachabilityError.FailedToCreateWithAddress(let address) {
         } catch ReachabilityError.FailedToCreateWithAddress(let address) {
-            networkStatus.textColor = UIColor.redColor()
+            networkStatus.textColor = .red
             networkStatus.text = "Unable to create\nReachability with address:\n\(address)"
             networkStatus.text = "Unable to create\nReachability with address:\n\(address)"
             return
             return
         } catch {}
         } catch {}
@@ -55,7 +55,7 @@ class ViewController: UIViewController {
                 self.updateLabelColourWhenNotReachable(reachability)
                 self.updateLabelColourWhenNotReachable(reachability)
             }
             }
         } else {
         } else {
-            NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:", name: ReachabilityChangedNotification, object: reachability)
+            NotificationCenter.default.addObserver(self, selector: #selector(ViewController.reachabilityChanged(_:)), name: ReachabilityChangedNotification, object: reachability)
         }
         }
     }
     }
     
     
@@ -64,7 +64,7 @@ class ViewController: UIViewController {
         do {
         do {
             try reachability?.startNotifier()
             try reachability?.startNotifier()
         } catch {
         } catch {
-            networkStatus.textColor = UIColor.redColor()
+            networkStatus.textColor = .red
             networkStatus.text = "Unable to start\nnotifier"
             networkStatus.text = "Unable to start\nnotifier"
             return
             return
         }
         }
@@ -73,34 +73,34 @@ class ViewController: UIViewController {
     func stopNotifier() {
     func stopNotifier() {
         print("--- stop notifier")
         print("--- stop notifier")
         reachability?.stopNotifier()
         reachability?.stopNotifier()
-        NSNotificationCenter.defaultCenter().removeObserver(self, name: ReachabilityChangedNotification, object: nil)
+        NotificationCenter.default.removeObserver(self, name: ReachabilityChangedNotification, object: nil)
         reachability = nil
         reachability = nil
     }
     }
     
     
-    func updateLabelColourWhenReachable(reachability: Reachability) {
+    func updateLabelColourWhenReachable(_ reachability: Reachability) {
         print("\(reachability.description) - \(reachability.currentReachabilityString)")
         print("\(reachability.description) - \(reachability.currentReachabilityString)")
-        if reachability.isReachableViaWiFi() {
-            self.networkStatus.textColor = UIColor.greenColor()
+        if reachability.isReachableViaWiFi {
+            self.networkStatus.textColor = .green
         } else {
         } else {
-            self.networkStatus.textColor = UIColor.blueColor()
+            self.networkStatus.textColor = .blue
         }
         }
         
         
         self.networkStatus.text = reachability.currentReachabilityString
         self.networkStatus.text = reachability.currentReachabilityString
     }
     }
     
     
-    func updateLabelColourWhenNotReachable(reachability: Reachability) {
+    func updateLabelColourWhenNotReachable(_ reachability: Reachability) {
         print("\(reachability.description) - \(reachability.currentReachabilityString)")
         print("\(reachability.description) - \(reachability.currentReachabilityString)")
         
         
-        self.networkStatus.textColor = UIColor.redColor()
+        self.networkStatus.textColor = .red
         
         
         self.networkStatus.text = reachability.currentReachabilityString
         self.networkStatus.text = reachability.currentReachabilityString
     }
     }
     
     
     
     
-    func reachabilityChanged(note: NSNotification) {
+    func reachabilityChanged(_ note: Notification) {
         let reachability = note.object as! Reachability
         let reachability = note.object as! Reachability
         
         
-        if reachability.isReachable() {
+        if reachability.isReachable {
             updateLabelColourWhenReachable(reachability)
             updateLabelColourWhenReachable(reachability)
         } else {
         } else {
             updateLabelColourWhenNotReachable(reachability)
             updateLabelColourWhenNotReachable(reachability)