AppDelegate.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. IQKeyboardManager.shared.enable = true
  20. self.window = UIWindow.init(frame: UIScreen.main.bounds)
  21. self.window?.backgroundColor = UIColor.white
  22. self.window?.makeKeyAndVisible()
  23. self.window?.makeKeyAndVisible()
  24. self.window?.makeKeyAndVisible()
  25. //默认域名
  26. // Defaults[\.BaseUrl] = "http://47.108.114.127:10888"
  27. // Defaults[\.BaseUrl] = "http://www.gzzzyd.com/gm-api"
  28. // Defaults[\.BaseUrl] = "http://wine.gzzzyd.com/api"
  29. Defaults[\.BaseUrl] = "https://kcapp.kiansengculinary.com/api"
  30. // Defaults[\.BaseUrl] = "https://kcapp.gzzzyd.com/api"
  31. // Defaults[\.BaseUrl] = "https://kcapp.gzzzyd.com/api"
  32. if Defaults[\.isFirstOpen]{
  33. self.gotoStartupPage()
  34. }else{
  35. if Defaults[\.UserToken] != nil{
  36. self.setHomeTabBarViewController()
  37. }else{
  38. self.gotoLogin()
  39. }
  40. }
  41. self.registerStripePayApi()
  42. return true
  43. }
  44. //注册StripeApi
  45. func registerStripePayApi(){
  46. // STPAPIClient.shared.publishableKey = "pk_test_51O3DvzBqBnSGwj1K0ePpneI04LzHX5e9JC0BYqLXfnEqhJJgaSdtUM7ppv3YaK0vTdJ5mUTSLoG84zIILjfsyglz00Cgl4haJ3"
  47. // STPPaymentConfiguration.shared.applePayEnabled = true
  48. // STPPaymentConfiguration.shared.appleMerchantIdentifier = "pk_test_51O3DvzBqBnSGwj1K0ePpneI04LzHX5e9JC0BYqLXfnEqhJJgaSdtUM7ppv3YaK0vTdJ5mUTSLoG84zIILjfsyglz00Cgl4haJ3"
  49. }
  50. //进入启动页
  51. func gotoStartupPage(){
  52. let vc = StartupPageViewController()
  53. self.window?.rootViewController = vc
  54. Defaults[\.isFirstOpen] = false
  55. }
  56. //MARK: 进入登录页
  57. func gotoLogin(){
  58. let vc = TCLogingViewController()
  59. let navMange = UINavigationController.init(rootViewController: vc)
  60. self.viewController = navMange
  61. self.window?.rootViewController = navMange
  62. // Defaults[\.isFirstOpen] = true
  63. // let loginVC = TCLogingViewController()
  64. // let keyWindow = UIApplication.shared.keyWindow
  65. // self.window?.rootViewController = loginVC
  66. }
  67. //MARK: 进入首页
  68. func setHomeTabBarViewController(){
  69. if Defaults[\.isSetPayPassword] === 0{
  70. let loginVC = EditPayPSWViewController()
  71. loginVC.phone = Defaults[\.UserPhone]
  72. self.window?.rootViewController = loginVC
  73. return
  74. }
  75. let tabVC = BaseTabbarController()
  76. tabVC.setupChildControllers()
  77. self.window?.rootViewController = tabVC
  78. }
  79. // MARK: UISceneSession Lifecycle
  80. // func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  81. // // Called when a new scene session is being created.
  82. // // Use this method to select a configuration to create the new scene with.
  83. // return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  84. // }
  85. //
  86. // func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  87. // // Called when the user discards a scene session.
  88. // // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  89. // // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  90. // }
  91. // MARK: - Core Data stack
  92. lazy var persistentContainer: NSPersistentContainer = {
  93. /*
  94. The persistent container for the application. This implementation
  95. creates and returns a container, having loaded the store for the
  96. application to it. This property is optional since there are legitimate
  97. error conditions that could cause the creation of the store to fail.
  98. */
  99. let container = NSPersistentContainer(name: "ADHTuanCan")
  100. container.loadPersistentStores(completionHandler: { (storeDescription, error) in
  101. if let error = error as NSError? {
  102. // Replace this implementation with code to handle the error appropriately.
  103. // 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.
  104. /*
  105. Typical reasons for an error here include:
  106. * The parent directory does not exist, cannot be created, or disallows writing.
  107. * The persistent store is not accessible, due to permissions or data protection when the device is locked.
  108. * The device is out of space.
  109. * The store could not be migrated to the current model version.
  110. Check the error message to determine what the actual problem was.
  111. */
  112. fatalError("Unresolved error \(error), \(error.userInfo)")
  113. }
  114. })
  115. return container
  116. }()
  117. // MARK: - Core Data Saving support
  118. func saveContext () {
  119. let context = persistentContainer.viewContext
  120. if context.hasChanges {
  121. do {
  122. try context.save()
  123. } catch {
  124. // Replace this implementation with code to handle the error appropriately.
  125. // 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.
  126. let nserror = error as NSError
  127. fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
  128. }
  129. }
  130. }
  131. }