AppDelegate.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // AppDelegate.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/9/27.
  6. //
  7. import UIKit
  8. import CoreData
  9. import IQKeyboardManagerSwift
  10. import SwiftyUserDefaults
  11. //import Stripe
  12. @main
  13. class AppDelegate: UIResponder, UIApplicationDelegate {
  14. var window: UIWindow?
  15. var viewController: UIViewController?
  16. var viewController1: UINavigationController!
  17. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  18. // Override point for customization after application launch.
  19. let languanges : [String] = UserDefaults.standard.object(forKey: "AppleLanguages") as! [String]
  20. let preferredLanguage = languanges.first
  21. if Defaults[\.LanguagesStr] != nil{
  22. }else{
  23. Defaults[\.LanguagesStr] = preferredLanguage
  24. }
  25. UserDefaults.standard.set([Defaults[\.LanguagesStr]], forKey: "AppleLanguages")
  26. UserDefaults.standard.synchronize()
  27. IQKeyboardManager.shared.enable = true
  28. self.window = UIWindow.init(frame: UIScreen.main.bounds)
  29. self.window?.backgroundColor = UIColor.white
  30. self.window?.makeKeyAndVisible()
  31. self.window?.makeKeyAndVisible()
  32. self.window?.makeKeyAndVisible()
  33. //默认域名
  34. // Defaults[\.BaseUrl] = "http://47.108.114.127:10888"
  35. // Defaults[\.BaseUrl] = "http://47.109.38.72:10887"
  36. // Defaults[\.BaseUrl] = "http://www.gzzzyd.com/gm-api"
  37. // Defaults[\.BaseUrl] = "http://wine.gzzzyd.com/api"
  38. // Defaults[\.BaseUrl] = "https://kcapp.kiansengculinary.com/api"
  39. // Defaults[\.BaseUrl] = "https://kcapp.gzzzyd.com/api"
  40. Defaults[\.BaseUrl] = "https://kscapp.kiansengculinary.com/api"
  41. // https://kscapp.kiansengculinary.com/api/
  42. // Defaults[\.BaseUrl] = "https://kcapp.gzzzyd.com/api"
  43. if Defaults[\.isFirstOpen]{
  44. self.gotoStartupPage()
  45. }else{
  46. if Defaults[\.UserToken] != nil{
  47. self.setHomeTabBarViewController()
  48. }else{
  49. self.gotoLogin()
  50. }
  51. }
  52. self.registerStripePayApi()
  53. return true
  54. }
  55. //注册StripeApi
  56. func registerStripePayApi(){
  57. // STPAPIClient.shared.publishableKey = "pk_test_51O3DvzBqBnSGwj1K0ePpneI04LzHX5e9JC0BYqLXfnEqhJJgaSdtUM7ppv3YaK0vTdJ5mUTSLoG84zIILjfsyglz00Cgl4haJ3"
  58. // STPPaymentConfiguration.shared.applePayEnabled = true
  59. // STPPaymentConfiguration.shared.appleMerchantIdentifier = "pk_test_51O3DvzBqBnSGwj1K0ePpneI04LzHX5e9JC0BYqLXfnEqhJJgaSdtUM7ppv3YaK0vTdJ5mUTSLoG84zIILjfsyglz00Cgl4haJ3"
  60. }
  61. //进入启动页
  62. func gotoStartupPage(){
  63. let vc = StartupPageViewController()
  64. self.window?.rootViewController = vc
  65. Defaults[\.isFirstOpen] = false
  66. }
  67. //MARK: 进入登录页
  68. func gotoLogin(){
  69. let vc = TCLogingViewController()
  70. let navMange = UINavigationController.init(rootViewController: vc)
  71. self.viewController = navMange
  72. self.window?.rootViewController = navMange
  73. // Defaults[\.isFirstOpen] = true
  74. // let loginVC = TCLogingViewController()
  75. // let keyWindow = UIApplication.shared.keyWindow
  76. // self.window?.rootViewController = loginVC
  77. }
  78. //MARK: 进入首页
  79. func setHomeTabBarViewController(){
  80. // if Defaults[\.isSetPayPassword] === 0{
  81. // let loginVC = EditPayPSWViewController()
  82. // loginVC.phone = Defaults[\.UserPhone]
  83. // self.window?.rootViewController = loginVC
  84. // return
  85. // }
  86. let tabVC = BaseTabbarController()
  87. tabVC.setupChildControllers()
  88. self.window?.rootViewController = tabVC
  89. }
  90. // MARK: UISceneSession Lifecycle
  91. // func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  92. // // Called when a new scene session is being created.
  93. // // Use this method to select a configuration to create the new scene with.
  94. // return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  95. // }
  96. //
  97. // func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  98. // // Called when the user discards a scene session.
  99. // // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  100. // // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  101. // }
  102. // MARK: - Core Data stack
  103. lazy var persistentContainer: NSPersistentContainer = {
  104. /*
  105. The persistent container for the application. This implementation
  106. creates and returns a container, having loaded the store for the
  107. application to it. This property is optional since there are legitimate
  108. error conditions that could cause the creation of the store to fail.
  109. */
  110. let container = NSPersistentContainer(name: "ADHTuanCan")
  111. container.loadPersistentStores(completionHandler: { (storeDescription, error) in
  112. if let error = error as NSError? {
  113. // Replace this implementation with code to handle the error appropriately.
  114. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  115. /*
  116. Typical reasons for an error here include:
  117. * The parent directory does not exist, cannot be created, or disallows writing.
  118. * The persistent store is not accessible, due to permissions or data protection when the device is locked.
  119. * The device is out of space.
  120. * The store could not be migrated to the current model version.
  121. Check the error message to determine what the actual problem was.
  122. */
  123. fatalError("Unresolved error \(error), \(error.userInfo)")
  124. }
  125. })
  126. return container
  127. }()
  128. // MARK: - Core Data Saving support
  129. func saveContext () {
  130. let context = persistentContainer.viewContext
  131. if context.hasChanges {
  132. do {
  133. try context.save()
  134. } catch {
  135. // Replace this implementation with code to handle the error appropriately.
  136. // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  137. let nserror = error as NSError
  138. fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
  139. }
  140. }
  141. }
  142. }