AppDelegate.swift 5.9 KB

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