123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // AppDelegate.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/6.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import IQKeyboardManagerSwift
- import PKHUD
- @UIApplicationMain
- class AppDelegate: UIResponder, UIApplicationDelegate {
- var window : UIWindow?
- var internetReachability : Reachability?
-
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
- // Override point for customization after application launch.
-
- if #available(iOS 13.0, *) {
-
- } else {
- //设置键盘
- IQKeyboardManager.shared.enable = true
-
- UINavigationBar.appearance().barStyle = .default
- //创建window
-
- self.window = UIWindow(frame: UIScreen.main.bounds)
- window?.backgroundColor = UIColor.white
- //创建根控制器
- let vc = IHLoginVCtr()
- window?.rootViewController = vc
- //显示界面
- window?.makeKeyAndVisible()
-
-
- }
-
- //添加一个系统通知
- NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged), name: NSNotification.Name.reachabilityChanged, object: nil)
- internetReachability = Reachability.forInternetConnection()
- internetReachability?.startNotifier()
- updateInterfaceWithReachability(reachability: internetReachability!)
-
-
- return true
- }
- //实时检查网络的状态 - 如果从storyboard里启动了,登录时检测不到网络
- @objc func reachabilityChanged(noti : Notification){
- let curReach = noti.object as! Reachability
-
- updateInterfaceWithReachability(reachability: curReach)
- }
-
- private func updateInterfaceWithReachability(reachability : Reachability){
-
- let netStatus = reachability.currentReachabilityStatus()
- let keywindow = UIApplication.shared.keyWindow
- log.debug("当前的网络状态\(netStatus)--\(keywindow)")
-
- guard let _ = keywindow else {
- return
- }
-
- switch netStatus {
- case NotReachable:
- HUD.flash(.label("当前网络状态不可用"), delay: 1)
- // case ReachableViaWiFi:
- // HUD.flash(.label("当前网络状态是wifi"), delay: 0.6)
- // case ReachableViaWWAN:
- // HUD.flash(.label("当前网络状态是蜂窝网"), delay: 1)
- default:
- break
- }
- }
- @available(iOS 13.0, *)
- func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
- // Called when a new scene session is being created.
- // Use this method to select a configuration to create the new scene with.
-
- return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
-
- }
- @available(iOS 13.0, *)
- func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
- // Called when the user discards a scene session.
- // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
- // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
- }
- }
|