ViewController.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // ViewController.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/10.
  6. //
  7. import UIKit
  8. import Alamofire
  9. class ViewController: UIViewController {
  10. private var timer: Timer?
  11. private var count = 0
  12. override func viewDidLoad() {
  13. super.viewDidLoad()
  14. self.checkNetwork()
  15. self.setUI()
  16. }
  17. @objc private func updateCountdown() {
  18. if(count > 6){
  19. self.contentLabel.isHidden = false
  20. self.oneButton.isHidden = false
  21. invalidateTimer()
  22. }
  23. count += 1
  24. }
  25. private func invalidateTimer() {
  26. timer?.invalidate()
  27. timer = nil
  28. }
  29. func setUI(){
  30. if timer == nil {
  31. timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateCountdown), userInfo: nil, repeats: true)
  32. RunLoop.current.add(timer!, forMode: .common)
  33. }
  34. self.view.addSubview(bgView)
  35. bgView.snp.makeConstraints { make in
  36. make.left.right.bottom.equalToSuperview()
  37. make.height.equalTo(131)
  38. }
  39. self.view.addSubview(bgLogoView)
  40. bgLogoView.snp.makeConstraints { make in
  41. make.size.equalTo(CGSize(width: 96, height: 96))
  42. make.centerX.equalToSuperview()
  43. make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(130)
  44. }
  45. self.view.addSubview(bgTitleView)
  46. bgTitleView.snp.makeConstraints { make in
  47. make.left.equalToSuperview().offset(96)
  48. make.right.equalToSuperview().offset(-96)
  49. make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom).offset(-40)
  50. make.height.equalTo(bgTitleView.snp.width).multipliedBy(156.0/501.0)
  51. }
  52. self.view.addSubview(contentLabel)
  53. contentLabel.snp.makeConstraints { make in
  54. make.size.equalTo(CGSize(width: QSLConst.qsl_kScreenW, height: 18.0.rpx))
  55. make.center.equalToSuperview()
  56. }
  57. self.view.addSubview(oneButton)
  58. oneButton.snp.makeConstraints { make in
  59. make.size.equalTo(CGSize(width: 140.rpx, height: 44.rpx))
  60. make.centerX.equalToSuperview()
  61. make.top.equalTo(contentLabel.snp.bottom).offset(20.rpx)
  62. }
  63. self.contentLabel.isHidden = true
  64. self.oneButton.isHidden = true
  65. }
  66. @objc func checkNetworkSetting(){
  67. if let url = URL(string: UIApplication.openSettingsURLString), UIApplication.shared.canOpenURL(url) {
  68. UIApplication.shared.open(url)
  69. }
  70. }
  71. @objc func checkNetwork(){
  72. NetworkReachabilityManager.default?.startListening(onUpdatePerforming: {[weak self] status in
  73. if(status != .notReachable){
  74. print("checkIDFA")
  75. UNUserNotificationCenter.current().requestAuthorization(
  76. options: [.alert, .sound, .badge]
  77. ) { granted, error in
  78. DispatchQueue.main.async {
  79. if granted {
  80. DispatchQueue.main.async {
  81. UIApplication.shared.registerForRemoteNotifications()
  82. }
  83. } else if let error = error {
  84. print("Error: \(error.localizedDescription)")
  85. }
  86. self?.intoMain()
  87. }
  88. }
  89. NetworkReachabilityManager.default?.stopListening()
  90. self?.invalidateTimer()
  91. }
  92. })
  93. }
  94. func intoMain() {
  95. self.contentLabel.isHidden = true
  96. self.oneButton.isHidden = true
  97. QSLBaseManager.shared.initConfig()
  98. // 是否通过引导页
  99. // let isShowGuideKey = UserDefaults.standard.bool(forKey: "isShowGuideKey")
  100. // if !isShowGuideKey {
  101. // // 引导页
  102. // UserDefaults.standard.set(true, forKey: "isShowGuideKey")
  103. // if let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate {
  104. // sceneDelegate.window?.rootViewController = QSLGuideController()
  105. // sceneDelegate.window?.makeKeyAndVisible()
  106. // }
  107. // } else {
  108. UNUserNotificationCenter.current().requestAuthorization(
  109. options: [.alert, .sound, .badge]
  110. ) { granted, error in
  111. DispatchQueue.main.async {
  112. if granted {
  113. DispatchQueue.main.async {
  114. UIApplication.shared.registerForRemoteNotifications()
  115. }
  116. } else if let error = error {
  117. print("Error: \(error.localizedDescription)")
  118. }
  119. }
  120. }
  121. QSLBaseManager.shared.initIDFA()
  122. // 主页
  123. if let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate {
  124. sceneDelegate.window?.rootViewController = CustomTabBarController()
  125. sceneDelegate.window?.makeKeyAndVisible()
  126. }
  127. // }
  128. }
  129. lazy var bgView: UIImageView = {
  130. let item = UIImageView()
  131. item.image = UIImage(named: "launch_bottom_bg")
  132. item.contentMode = .scaleToFill
  133. return item
  134. }()
  135. lazy var bgLogoView: UIImageView = {
  136. let item = UIImageView()
  137. item.image = UIImage(named: "launch_icon")
  138. item.contentMode = .scaleToFill
  139. return item
  140. }()
  141. lazy var bgTitleView: UIImageView = {
  142. let item = UIImageView()
  143. item.image = UIImage(named: "launch_title")
  144. item.contentMode = .scaleToFill
  145. return item
  146. }()
  147. lazy var contentLabel: UILabel = {
  148. let label = UILabel()
  149. label.text("网络错误,请检查网络权限")
  150. label.font(16)
  151. label.textColor = .black
  152. label.textAlignment = .center
  153. return label
  154. }()
  155. lazy var oneButton: UIButton = {
  156. let btn = UIButton()
  157. btn.addRadius(radius: 22.rpx)
  158. btn.title("去设置")
  159. btn.textColor(.white)
  160. btn.mediumFont(14)
  161. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 250.rpx, height: 44.rpx, direction: .horizontal)
  162. btn.addTarget(self, action: #selector(checkNetworkSetting), for: .touchUpInside)
  163. return btn
  164. }()
  165. // 用户协议跳转
  166. func agreementAction() {
  167. let vc = QSLWebViewController()
  168. vc.webUrl = QSLConfig.AppServiceAgreementLink
  169. vc.title = "用户协议"
  170. vc.isShowTop = true
  171. self.present(vc, animated: true)
  172. }
  173. // 隐私协议跳转
  174. func privacyAction() {
  175. let vc = QSLWebViewController()
  176. vc.webUrl = QSLConfig.AppPrivacyAgreementLink
  177. vc.title = "隐私政策"
  178. vc.isShowTop = true
  179. self.present(vc, animated: true)
  180. }
  181. }