AppDelegate.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. //
  2. // AppDelegateSwift.swift
  3. // MCPlus
  4. //
  5. // Created by seo ha on 13/02/2019.
  6. // Copyright © 2019 KangSH. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. import CoreData
  11. import CoreNFC
  12. import ReplayKit
  13. import Fabric
  14. import Crashlytics
  15. @UIApplicationMain
  16. class AppDelegate: UIResponder, UIApplicationDelegate {
  17. var window: UIWindow?
  18. fileprivate var obf:Obfuscator = Obfuscator(withSalt: ["mcareplus" as AnyObject])
  19. @available(iOS 10, *)
  20. var persistentContainer:NSPersistentContainer{
  21. // MARK: - Core Data stack
  22. let _persistentContainer = NSPersistentContainer(name: "MCPlus")
  23. _persistentContainer.loadPersistentStores { (storeDescription, error) in
  24. if error != nil{
  25. // Replace this implementation with code to handle the error appropriately.
  26. // abort() 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.
  27. /*
  28. Typical reasons for an error here include:
  29. * The parent directory does not exist, cannot be created, or disallows writing.
  30. * The persistent store is not accessible, due to permissions or data protection when the device is locked.
  31. * The device is out of space.
  32. * The store could not be migrated to the current model version.
  33. Check the error message to determine what the actual problem was.
  34. */
  35. abort()
  36. }
  37. }
  38. return _persistentContainer
  39. }
  40. var userDefaults:UserDefaults = UserDefaults.standard
  41. var resURL:String?
  42. enum ALERT_TAG:Int {
  43. case UPDATE = 1
  44. case CANCEL = 2
  45. }
  46. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  47. Fabric.with([Crashlytics.self])
  48. self.versionCheck()
  49. if let nav = self.window?.rootViewController as? UINavigationController{
  50. nav.delegate = self
  51. }
  52. #if DEBUG
  53. print("디버깅 모드 입니다.")
  54. #else
  55. //안티디버거
  56. disable_attach()
  57. #endif
  58. return true
  59. }
  60. func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
  61. if userActivity.activityType != NSUserActivityTypeBrowsingWeb{
  62. return false
  63. }
  64. // Confirm that the NSUserActivity object contains a valid NDEF message.
  65. if #available(iOS 12.0, *) {
  66. let ndefMessage = userActivity.ndefMessagePayload
  67. if ndefMessage.records.count <= 0 || ndefMessage.records.first?.typeNameFormat == NFCTypeNameFormat.empty {
  68. return false
  69. }
  70. }
  71. return true
  72. }
  73. func applicationDidEnterBackground(_ application: UIApplication) {
  74. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  75. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  76. if let cookies = HTTPCookieStorage.shared.cookies{
  77. let cookieData = NSKeyedArchiver.archivedData(withRootObject: cookies)
  78. self.userDefaults.set(cookieData, forKey: "Cookies")
  79. }
  80. }
  81. func applicationDidBecomeActive(_ application: UIApplication) {
  82. // self.versionCheck()
  83. //화면잠금 모드로 고고씽
  84. // 지문인식을 받기 위해 지문인식 창이 떴다가 다시 돌아오는 경우도 applicationDidBecomeActive: 함수가 호출된다
  85. // let formatString = "yyyy-MM-dd hh:mm:ss"
  86. // let now = Date()
  87. // let savedTime = (self.userDefaults.object(forKey: "fingerprintAuthTime") as? String)?.fromDate(format: formatString)
  88. //
  89. // let diff = (savedTime?.timeIntervalSince(now) ?? 0) * -1
  90. //
  91. // if diff > 1 || savedTime == nil{
  92. // do{
  93. // guard let info = Bundle.main.infoDictionary else{ return }
  94. //
  95. // if info["LockScreenUse"] as? Bool == true{
  96. // let VC = ScreenLockViewController()
  97. // VC.modalPresentationStyle = .fullScreen
  98. // self.window?.rootViewController?.present(VC, animated: true, completion: nil)
  99. // }
  100. // }
  101. // }
  102. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  103. if let cookiesData = self.userDefaults.object(forKey: "Cookies") as? Data{
  104. do{
  105. guard let cookies = NSKeyedUnarchiver.unarchiveObject(with: cookiesData) as? [HTTPCookie] else{ return }
  106. for cookie in cookies{
  107. HTTPCookieStorage.shared.setCookie(cookie)
  108. }
  109. }
  110. }
  111. }
  112. func applicationWillTerminate(_ application: UIApplication) {
  113. if #available(iOS 10.0, *){
  114. saveContext()
  115. }
  116. }
  117. }
  118. extension AppDelegate{
  119. // MARK: - Core Data Saving support
  120. @available(iOS 10, *)
  121. func saveContext(){
  122. let context = persistentContainer.viewContext
  123. guard context.hasChanges == true else {
  124. do{
  125. try context.save()
  126. }catch{
  127. abort()
  128. }
  129. return
  130. }
  131. }
  132. func showAlertWithTag(tag:ALERT_TAG){
  133. switch tag {
  134. case .UPDATE:
  135. self.visibleViewController?.showAlert("", "version update alarm message".localized, "update".localized, "cancel".localized, { [weak self](action) in
  136. guard let res = self?.resURL, let url = URL(string: res) else{
  137. exit(0)
  138. }
  139. if #available(iOS 10.0, *) {
  140. UIApplication.shared.open(url, options: [UIApplication.OpenExternalURLOptionsKey : Any](), completionHandler: nil)
  141. }else{
  142. UIApplication.shared.openURL(url)
  143. }
  144. }, { [weak self](action) in
  145. //취소 누름
  146. self?.showAlertWithTag(tag: .CANCEL)
  147. })
  148. case .CANCEL:
  149. self.visibleViewController?.showAlert("", "update cancel alarm message".localized, "ok".localized, nil, { (action) in
  150. exit(0)
  151. })
  152. }
  153. }
  154. func versionCheck(){
  155. var param = [String:Any]()
  156. param["platformType"] = Constants.PLATFORM_TYPE
  157. param["appName"] = MCarePlusConstants.APP_NAME
  158. param["certType"] = MCarePlusConstants.CERT_TYPE
  159. var versionCheckUrl:String = "\(MCarePlusConstants.DOMAIN_NAME)\(MCarePlusConstants.APP_NAME)\(Constants.API_TYPE_VERSION_CHECK).json"
  160. let infoDic:Dictionary = Bundle.main.infoDictionary!
  161. let appName = infoDic["CFBundleName"] as? String
  162. if appName!.isEqualToString(find: "lemon_local") {
  163. versionCheckUrl = "\(MCarePlusConstants.DOMAIN_NAME)mcare-plus\(Constants.API_TYPE_VERSION_CHECK).json"
  164. }
  165. APIClient(versionCheckUrl)
  166. .param(reqParam: param)
  167. .enType(.json)
  168. .connect { [weak self](result:[String:Any]) in
  169. guard let info = Bundle.main.infoDictionary, let currentVersionString = info["CFBundleShortVersionString"] as? String, let currentVersion = Float(currentVersionString) else{ return }
  170. let versionOrder = result["versionOrder"] as? Float ?? 0
  171. if versionOrder > currentVersion{
  172. // 업데이트 필요
  173. self?.resURL = result["marketUrl"] as? String
  174. self?.showAlertWithTag(tag: .UPDATE)
  175. }else{
  176. print("최신 버전이 설치되어 있음.")
  177. }
  178. self?.cpzmdkdldhdptmfnxld()
  179. }
  180. }
  181. //MARK: = RootingCheck
  182. //checkiOSRooting
  183. func cpzmdkdldhdptmfnxld() {
  184. // let rootingCheck:MCareMessageRequestProtocol!
  185. // let crackCehck:TGfgWLPFSsedkMjVFwzECGIJlWLmXNHAProtocol!
  186. // rootingCheck
  187. let fnxldcpzm = MCareMessageRequest()
  188. // crackchek
  189. let zmforcpzm = TGfgWLPFSsedkMjVFwzECGIJlWLmXNHA1()
  190. //폰이 루팅 되어 있는지 체크한다.
  191. if fnxldcpzm.isMsgRequest() {
  192. let rootingMsg:String = NSLocalizedString("RootingWarnningMessage", comment: obf.reveal(key:[176, 206, 203, 140, 254, 224, 157, 227, 197, 159, 192, 219, 77, 143, 198, 242, 137, 235, 252, 152, 230, 197, 183, 202, 227, 65, 158, 240, 250, 128, 255, 198, 182, 208, 229, 136, 234, 214, 75]))
  193. let rootingTitle:String = NSLocalizedString("AlertTitleWarnning", comment: "경고")
  194. self.visibleViewController?.showAlert(rootingTitle, rootingMsg, "닫기")
  195. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  196. exit(0)
  197. }
  198. }
  199. let crackResult:String = zmforcpzm.RrSysWIEJNXJSjLdLYdkUhuSZCTsCzYc()
  200. //크랙 여부를 체크한다.
  201. if !(crackResult == CommonConstants.CRACK_CODE_1001) {
  202. var crackMsg:String = NSLocalizedString("CrackWarnningMessage", comment: obf.reveal(key:[183, 248, 210, 141, 239, 209, 80, 129, 244, 223, 182, 197, 244, 136, 241, 234, 137, 230, 216, 85, 159, 214, 255, 128, 245, 232, 159, 240, 208, 128, 253, 235, 125, 183, 250, 229, 141, 248, 208, 155, 231, 253, 152, 214, 255, 67]))
  203. crackMsg = crackMsg.appending("\n").appending(crackResult)
  204. let crackTitle:String = NSLocalizedString("AlertTitleWarnning", comment: "경고")
  205. self.visibleViewController?.showAlert(crackTitle, crackMsg, "닫기")
  206. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  207. exit(0)
  208. }
  209. }
  210. }
  211. }
  212. extension AppDelegate:UINavigationControllerDelegate{
  213. func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
  214. if navigationController.viewControllers.first == viewController{
  215. navigationController.navigationBar.isHidden = true
  216. }else{
  217. navigationController.navigationBar.isHidden = false
  218. }
  219. }
  220. }