Utils.swift 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220
  1. //
  2. // Utils.swift
  3. // Runner
  4. //
  5. // Created by Rifqy Fakhrul Rijal on 13/08/20.
  6. // Copyright © 2020 The Chromium Authors. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. import NotificationBannerSwift
  11. import nuSDKService
  12. import CoreLocation
  13. //import var CommonCrypto.CC_MD5_DIGEST_LENGTH
  14. //import func CommonCrypto.CC_MD5
  15. //import typealias CommonCrypto.CC_LONG
  16. public final class Utils {
  17. public static func getCurrentTime()->Int64 {
  18. return Int64(Date().timeIntervalSince1970)
  19. }
  20. public static func getCurrentTimeMillis()->Int64 {
  21. return Int64(Date().timeIntervalSince1970 * 1000)
  22. }
  23. public static func getCurrentTimeNanos()->Int64 {
  24. return Int64(Date().timeIntervalSince1970 * 1000_000_000)
  25. }
  26. public static func getElapsedRealtime() -> Int64 {
  27. return Int64((ProcessInfo().systemUptime).rounded()) // SystemClock.elapsedRealtime();
  28. }
  29. public static func getElapsedRealtimeMillis() -> Int64 {
  30. return Int64((ProcessInfo().systemUptime * 1000).rounded()) // SystemClock.elapsedRealtime();
  31. }
  32. public static func getElapsedRealtimeNanos() -> Int64 {
  33. return Int64((ProcessInfo().systemUptime * 1000_000_000).rounded()) // SystemClock.elapsedRealtimeNano();
  34. }
  35. public static func getForceAnonymous() -> Bool {
  36. return UserDefaults.standard.bool(forKey: "force_anonymous")
  37. }
  38. public static func setForceAnonymous(value: Bool){
  39. UserDefaults.standard.set(value, forKey: "force_anonymous")
  40. }
  41. public static func getSetProfile() -> Bool {
  42. return UserDefaults.standard.bool(forKey: "is_change_profile")
  43. }
  44. public static func setProfile(value: Bool){
  45. UserDefaults.standard.set(value, forKey: "is_change_profile")
  46. }
  47. static func setIconCenterAnim2(value: String){
  48. UserDefaults.standard.set(value, forKey: "pb_fb_icon_center_self_mode2")
  49. }
  50. static func getIconCenterAnim2() -> String {
  51. UserDefaults.standard.string(forKey: "pb_fb_icon_center_self_mode2") ?? ""
  52. }
  53. static func setIconCenterAnim4(value: String){
  54. UserDefaults.standard.set(value, forKey: "pb_fb_icon_center_self_mode4")
  55. }
  56. static func getIconCenterAnim4() -> String {
  57. UserDefaults.standard.string(forKey: "pb_fb_icon_center_self_mode4") ?? ""
  58. }
  59. static func setURLFirstTab(value: String) {
  60. UserDefaults.standard.set(value, forKey: "app_builder_url_first_tab")
  61. }
  62. static func setURLThirdTab(value: String) {
  63. UserDefaults.standard.set(value, forKey: "app_builder_url_third_tab")
  64. }
  65. static func setURLBase(value: String) {
  66. UserDefaults.standard.set(value, forKey: "app_builder_url_base")
  67. }
  68. static func setURLQMS(value: String) {
  69. UserDefaults.standard.set(value, forKey: "app_builder_url_qms")
  70. }
  71. static func setIconDock(value: String) {
  72. UserDefaults.standard.set(value, forKey: "app_builder_icon_dock")
  73. }
  74. static func setIconSS(value: String) {
  75. UserDefaults.standard.set(value, forKey: "app_builder_icon_ss")
  76. }
  77. static func setBackground(value: String) {
  78. UserDefaults.standard.set(value, forKey: "app_builder_background")
  79. }
  80. static func setURLPrivacyPolicy(value: String){
  81. UserDefaults.standard.set(value, forKey: "app_builder_url_privacy_policy")
  82. }
  83. static func setEnablePrivacyPolicy(value: Bool){
  84. UserDefaults.standard.set(value, forKey: "app_builder_enable_privacy_policy")
  85. }
  86. static func setCustomTab(cust: String){
  87. UserDefaults.standard.set(cust, forKey: "custom_tab")
  88. }
  89. static func setACTheme(value: String){
  90. UserDefaults.standard.set(value, forKey: "app_builder_ac_theme")
  91. }
  92. static func setButtonURL(value: String){
  93. UserDefaults.standard.set(value, forKey: "app_builder_button_url")
  94. }
  95. static func setCustomButtons(value: String){
  96. UserDefaults.standard.set(value, forKey: "app_builder_custom_buttons")
  97. }
  98. public static func getCustomButtons() -> String {
  99. UserDefaults.standard.string(forKey: "app_builder_custom_buttons") ?? ""
  100. }
  101. static func setCustomFBIcon(value: String){
  102. UserDefaults.standard.set(value, forKey: "app_builder_button_icon")
  103. }
  104. static func getCustomFBIcon() -> String {
  105. UserDefaults.standard.string(forKey: "app_builder_button_icon") ?? ""
  106. }
  107. static func setEnableMobileBuilder(value: String){
  108. UserDefaults.standard.set(value, forKey: "app_builder_enable_mobile_builder")
  109. }
  110. public static func getEnableMobileBuilder() -> String {
  111. UserDefaults.standard.string(forKey: "app_builder_enable_mobile_builder") ?? "0"
  112. }
  113. static func setFinishInitPrefs(value: Bool){
  114. UserDefaults.standard.set(value, forKey: "finish_init_prefs")
  115. }
  116. public static func getFinishInitPrefsr() -> Bool {
  117. UserDefaults.standard.bool(forKey: "finish_init_prefs")
  118. }
  119. static func setConfigModeFB(value: String) {
  120. UserDefaults.standard.set(value, forKey: "fb_config_mode")
  121. }
  122. static func getConfigModeFB() -> String {
  123. UserDefaults.standard.string(forKey: "fb_config_mode") ?? "1"
  124. }
  125. static func setCookiesMobile(value: String) {
  126. UserDefaults.standard.set(value, forKey: "cookies_mobile")
  127. }
  128. public static func getCookiesMobile() -> String {
  129. UserDefaults.standard.string(forKey: "cookies_mobile") ?? ""
  130. }
  131. static func getBackground() -> String {
  132. return UserDefaults.standard.string(forKey: "app_builder_background") ?? ""
  133. }
  134. static func setBackgroundLight(value: String) {
  135. UserDefaults.standard.set(value, forKey: "app_builder_background_light")
  136. }
  137. static func getBackgroundLight() -> String {
  138. UserDefaults.standard.string(forKey: "app_builder_background_light") ?? ""
  139. }
  140. static func setBackgroundDark(value: String) {
  141. UserDefaults.standard.set(value, forKey: "app_builder_background_dark")
  142. }
  143. static func getBackgroundDark() -> String {
  144. UserDefaults.standard.string(forKey: "app_builder_background_dark") ?? ""
  145. }
  146. static func setMaxRetryUpload(value: String) {
  147. UserDefaults.standard.set(value, forKey: "max_retry_upload")
  148. }
  149. static func getMaxRetryUpload() -> String {
  150. UserDefaults.standard.string(forKey: "max_retry_upload") ?? "5"
  151. }
  152. static func setMaxRetryTimeUpload(value: String) {
  153. UserDefaults.standard.set(value, forKey: "max_retry_time_upload")
  154. }
  155. static func getMaxRetryTimeUpload() -> String {
  156. UserDefaults.standard.string(forKey: "max_retry_time_upload") ?? "60000"
  157. }
  158. static func setWhatsappCenter(value: String) {
  159. UserDefaults.standard.set(value, forKey: "whatsapp_center")
  160. }
  161. static func getWhatsappCenter() -> String {
  162. UserDefaults.standard.string(forKey: "whatsapp_center") ?? "08115881946"
  163. }
  164. static func setSMSCenter(value: String) {
  165. UserDefaults.standard.set(value, forKey: "sms_center")
  166. }
  167. static func getSMSCenter() -> String {
  168. UserDefaults.standard.string(forKey: "sms_center") ?? "081290009799"
  169. }
  170. static func setCallCenter(value: String) {
  171. UserDefaults.standard.set(value, forKey: "call_center")
  172. }
  173. static func getCallCenter() -> String {
  174. UserDefaults.standard.string(forKey: "call_center") ?? "1500046"
  175. }
  176. public static func sGetCurrentDateTime(sFormat: String!) -> String! {
  177. let todaysDate = NSDate()
  178. let dateFormatter = DateFormatter()
  179. dateFormatter.dateFormat = sFormat
  180. return dateFormatter.string(from: todaysDate as Date)
  181. }
  182. // public static func getMD5(string: String) -> Data {
  183. // let length = Int(CC_MD5_DIGEST_LENGTH)
  184. // let messageData = string.data(using:.utf8)!
  185. // var digestData = Data(count: length)
  186. //
  187. // _ = digestData.withUnsafeMutableBytes { digestBytes -> UInt8 in
  188. // messageData.withUnsafeBytes { messageBytes -> UInt8 in
  189. // if let messageBytesBaseAddress = messageBytes.baseAddress, let digestBytesBlindMemory = digestBytes.bindMemory(to: UInt8.self).baseAddress {
  190. // let messageLength = CC_LONG(messageData.count)
  191. // CC_MD5(messageBytesBaseAddress, messageLength, digestBytesBlindMemory)
  192. // }
  193. // return 0
  194. // }
  195. // }
  196. // return digestData
  197. // }
  198. public static let callDurationFormatter: DateComponentsFormatter = {
  199. let dateFormatter: DateComponentsFormatter
  200. dateFormatter = DateComponentsFormatter()
  201. dateFormatter.unitsStyle = .positional
  202. dateFormatter.allowedUnits = [.minute, .second]
  203. dateFormatter.zeroFormattingBehavior = .pad
  204. return dateFormatter
  205. }()
  206. public static func previewMessageText(chat: Chat) -> Any {
  207. if chat.credential == "1" && chat.lock == "2" {
  208. return ("🚫 _"+"Message has expired".localized()+"_").richText(group_id: chat.pin)
  209. } else if chat.credential == "1" {
  210. return "Confidential Message".localized().richText(group_id: chat.pin)
  211. } else if chat.attachmentFlag == "27" {
  212. return ("📄 " + "Live Streaming".localized()).richText(group_id: chat.pin)
  213. } else if chat.attachmentFlag == "26" {
  214. return ("📄 " + "Seminar".localized()).richText(group_id: chat.pin)
  215. } else if !chat.image.isEmpty {
  216. if !chat.messageText.isEmpty {
  217. return "📷 \(chat.messageText)".richText(group_id: chat.pin)
  218. } else {
  219. return ("📷 " + "Photo".localized()).richText(group_id: chat.pin)
  220. }
  221. }
  222. else if !chat.video.isEmpty {
  223. if !chat.messageText.isEmpty {
  224. return "📹 \(chat.messageText)".richText(group_id: chat.pin)
  225. } else {
  226. return ("📹 " + "Video".localized()).richText(group_id: chat.pin)
  227. }
  228. }
  229. else if !chat.file.isEmpty {
  230. if chat.messageScope == "18" {
  231. return ("📄 Form").richText(group_id: chat.pin)
  232. }
  233. return ("📄 " + chat.messageText.components(separatedBy: "|")[0]).richText(group_id: chat.pin)
  234. } else if chat.attachmentFlag == "11" {
  235. return ("❤️ " + "Sticker".localized()).richText(group_id: chat.pin)
  236. }
  237. else {
  238. return chat.messageText.richText(group_id: chat.pin)
  239. }
  240. }
  241. static func getURLBase() -> String {
  242. return UserDefaults.standard.string(forKey: "app_builder_url_base") ?? "https://nexilis.io/"
  243. }
  244. static func getIconDock() -> String {
  245. return UserDefaults.standard.string(forKey: "app_builder_icon_dock") ?? ""
  246. }
  247. static func getUrlDock() -> String? {
  248. return Utils.getURLBase() + "get_file_from_path?img=" + Utils.getIconDock()
  249. }
  250. static func setDefaultCC(value: String){
  251. UserDefaults.standard.set(value, forKey: "default_cc")
  252. }
  253. static func getDefaultCC() -> String? {
  254. return UserDefaults.standard.string(forKey: "default_cc")
  255. }
  256. static func setFloatingAnim(value: String){
  257. UserDefaults.standard.set(value, forKey: "fb_floating_anim")
  258. }
  259. static func getFloatingAnim() -> String {
  260. return UserDefaults.standard.string(forKey: "fb_floating_anim") ?? "1~1"
  261. }
  262. static func setFBIconBg(value: String){
  263. UserDefaults.standard.set(value, forKey: "fb_icon_with_bg")
  264. }
  265. static func getFBIconBg() -> String {
  266. return UserDefaults.standard.string(forKey: "fb_icon_with_bg") ?? "1"
  267. }
  268. static func setFBItemBg(value: String){
  269. UserDefaults.standard.set(value, forKey: "fb_item_with_bg")
  270. }
  271. static func getFBItemBg() -> String {
  272. return UserDefaults.standard.string(forKey: "fb_item_with_bg") ?? "1"
  273. }
  274. static func setDomainOpr(value: String){
  275. UserDefaults.standard.set(value, forKey: "domain_opr")
  276. }
  277. static func getDomainOpr() -> String {
  278. return UserDefaults.standard.string(forKey: "domain_opr") ?? "https://nexilis.io/"
  279. }
  280. static func setIpPortOpr(value: String){
  281. UserDefaults.standard.set(value, forKey: "ip_opr")
  282. }
  283. static func getIpOpr() -> String {
  284. return UserDefaults.standard.string(forKey: "ip_opr") ?? "34.101.172.194:42823"
  285. }
  286. static func setHarcodedIp(value: String){
  287. UserDefaults.standard.set(value, forKey: "harcoded_ip")
  288. }
  289. static func getHarcodedIp() -> String {
  290. return UserDefaults.standard.string(forKey: "harcoded_ip") ?? ""
  291. }
  292. static func setUserAgent(value: String){
  293. UserDefaults.standard.set(value, forKey: "user_agent")
  294. }
  295. public static func getUserAgent() -> String {
  296. return UserDefaults.standard.string(forKey: "user_agent") ?? "easySoftIndonesia"
  297. }
  298. public static func fetchDataWithCookiesAndUserAgent(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
  299. var request = URLRequest(url: url)
  300. request.httpMethod = "GET"
  301. request.setValue(Utils.getUserAgent(), forHTTPHeaderField: "User-Agent")
  302. request.setValue(Utils.getCookiesMobile(), forHTTPHeaderField: "Cookie")
  303. //print("DATA SEND MOBILE \(Utils.getUserAgent()) <> \(Utils.getCookiesMobile())")
  304. let urlConfig = URLSessionConfiguration.default
  305. let sessionDelegate = SelfSignedURLSessionDelegate()
  306. let session = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil)
  307. let task = session.dataTask(with: request, completionHandler: completion)
  308. task.resume()
  309. }
  310. public static func postDataWithCookiesAndUserAgent(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
  311. let parameters = [
  312. "apikey": UserDefaults.standard.string(forKey: "apiKey") ?? "",
  313. "f_pin": UserDefaults.standard.string(forKey: "me") ?? ""
  314. ]
  315. var jsonArray: [[String: Any]] = []
  316. jsonArray.append(parameters)
  317. guard let jsonData = try? JSONSerialization.data(withJSONObject: jsonArray, options: []) else {
  318. //print("Error: Unable to convert JSON array to data")
  319. return
  320. }
  321. var request = URLRequest(url: url)
  322. request.httpMethod = "POST"
  323. request.setValue(Utils.getUserAgent(), forHTTPHeaderField: "User-Agent")
  324. request.setValue(Utils.getCookiesMobile(), forHTTPHeaderField: "Cookie")
  325. request.setValue("application/json;charset=UTF-8", forHTTPHeaderField: "Content-Type")
  326. request.setValue("application/json", forHTTPHeaderField: "Accept")
  327. request.httpBody = jsonData
  328. //print("DATA SEND MOBILE \(Utils.getUserAgent()) <> \(Utils.getCookiesMobile())")
  329. let urlConfig = URLSessionConfiguration.default
  330. let sessionDelegate = SelfSignedURLSessionDelegate()
  331. let session = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil)
  332. let task = session.dataTask(with: request, completionHandler: completion)
  333. task.resume()
  334. }
  335. public static func resetValueSuperApp() {
  336. Utils.setURLFirstTab(value: "")
  337. Utils.setURLThirdTab(value: "")
  338. Utils.setURLWv3(value: "")
  339. Utils.setURLWv4(value: "")
  340. Utils.setURLWv5(value: "")
  341. Utils.setURLWv6(value: "")
  342. Utils.setCustomTab(cust: "")
  343. Utils.setIconDock(value: "")
  344. Utils.setBackground(value: "")
  345. Utils.setBackgroundLight(value: "")
  346. Utils.setBackgroundDark(value: "")
  347. Utils.setBackgroundTab1(value: "")
  348. Utils.setBackgroundTab2(value: "")
  349. Utils.setBackgroundTab3(value: "")
  350. Utils.setBackgroundTab4(value: "")
  351. Utils.setBackgroundTab5(value: "")
  352. Utils.setBackgroundTab6(value: "")
  353. Utils.setCpaasMode(mode: 0)
  354. Utils.setCustomButtons(value: "")
  355. Utils.setIconDock(value: "")
  356. Utils.setTab1Icon(value: "")
  357. Utils.setTab2Icon(value: "")
  358. Utils.setTab3Icon(value: "")
  359. Utils.setTab4Icon(value: "")
  360. Utils.setTab5Icon(value: "")
  361. Utils.setTab6Icon(value: "")
  362. Utils.setButtonIcon(value: "")
  363. Utils.setReverseTab(value: "")
  364. Utils.setIconDockSize(value: "")
  365. }
  366. public static func setValueInitialApp(data: String) {
  367. if let jsonArray = try! JSONSerialization.jsonObject(with: data.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [AnyObject] {
  368. do {
  369. for json in jsonArray {
  370. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_url_first_tab" {
  371. Utils.setURLFirstTab(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  372. }
  373. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_url_third_tab" {
  374. Utils.setURLThirdTab(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  375. }
  376. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_custom_tab" {
  377. Utils.setCustomTab(cust: json[CoreMessage_TMessageKey.VALUE] as! String)
  378. }
  379. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_url_base" {
  380. Utils.setURLBase(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  381. }
  382. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_url_qms" {
  383. Utils.setURLQMS(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  384. }
  385. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_icon_dock" {
  386. Utils.setIconDock(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  387. }
  388. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_icon_ss" {
  389. Utils.setIconSS(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  390. }
  391. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_background" {
  392. Utils.setBackground(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  393. }
  394. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_url_privacy_policy" {
  395. Utils.setURLPrivacyPolicy(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  396. }
  397. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_enable_privacy_policy" {
  398. Utils.setEnablePrivacyPolicy(value: json[CoreMessage_TMessageKey.VALUE] as! String == "1" ? true : false)
  399. }
  400. if json[CoreMessage_TMessageKey.KEY] as! String == "pb_fb_icon_center_self_mode2" {
  401. Utils.setIconCenterAnim2(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  402. }
  403. if json[CoreMessage_TMessageKey.KEY] as! String == "pb_fb_icon_center_self_mode4" {
  404. Utils.setIconCenterAnim4(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  405. }
  406. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_ac_theme" {
  407. Utils.setACTheme(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  408. }
  409. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_button_url" {
  410. Utils.setButtonURL(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  411. }
  412. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_custom_buttons" {
  413. Utils.setCustomButtons(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  414. }
  415. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_enable_mobile_builder" {
  416. Utils.setEnableMobileBuilder(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  417. }
  418. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_enable_mobile_builder" {
  419. Utils.setEnableMobileBuilder(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  420. }
  421. if json[CoreMessage_TMessageKey.KEY] as! String == "fb_config_mode" {
  422. Utils.setConfigModeFB(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  423. }
  424. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_button_icon" {
  425. Utils.setCustomFBIcon(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  426. }
  427. if json[CoreMessage_TMessageKey.KEY] as! String == "fb_floating_anim" {
  428. Utils.setFloatingAnim(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  429. }
  430. if json[CoreMessage_TMessageKey.KEY] as! String == "fb_icon_with_bg" {
  431. Utils.setFBIconBg(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  432. }
  433. if json[CoreMessage_TMessageKey.KEY] as! String == "fb_item_with_bg" {
  434. Utils.setFBItemBg(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  435. }
  436. if json[CoreMessage_TMessageKey.KEY] as! String == "user_agent" {
  437. Utils.setUserAgent(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  438. }
  439. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_background_light" {
  440. Utils.setBackgroundLight(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  441. }
  442. if json[CoreMessage_TMessageKey.KEY] as! String == "app_builder_background_dark" {
  443. Utils.setBackgroundDark(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  444. }
  445. if json[CoreMessage_TMessageKey.KEY] as! String == "sms_center" {
  446. Utils.setSMSCenter(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  447. }
  448. if json[CoreMessage_TMessageKey.KEY] as! String == "whatsapp_center" {
  449. Utils.setWhatsappCenter(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  450. }
  451. if json[CoreMessage_TMessageKey.KEY] as! String == "call_center" {
  452. Utils.setCallCenter(value: json[CoreMessage_TMessageKey.VALUE] as! String)
  453. }
  454. }
  455. } catch {
  456. }
  457. }
  458. }
  459. public static var inTabChats = false
  460. public static var longitude = ""
  461. public static var latitude = ""
  462. private static let I_BB = 48 // 0
  463. private static let I_BBT_1 = 57 // 9
  464. private static let I_BAT_1 = 65 // A
  465. private static let I_BBT_2 = 90 // Z
  466. private static let I_BAT_2 = 97 // a
  467. private static let I_BA = 122 // z
  468. private static let IC_BB = 33 // !
  469. private static let IC_BBT_1 = 47 // /
  470. private static let IC_BAT_1 = 58 // :
  471. private static let IC_BBT_2 = 64 // @
  472. private static let IC_BAT_2 = 91 // [
  473. private static let IC_BBT_3 = 96 // @
  474. private static let IC_BAT_3 = 123 // [
  475. private static let IC_BA = 126 // `
  476. private static var icIGNORE = Set<Int>()
  477. private static func initIcIgnore() {
  478. icIGNORE.insert(10)// \r
  479. icIGNORE.insert(13)// \n
  480. icIGNORE.insert(32)// <space>
  481. }
  482. public static func decrypt(str: String) -> String {
  483. var arr: [Character]
  484. var iRandom = 0
  485. var sDecrypt: String
  486. iRandom = Int(str.substring(from: 0, to: 0)) ?? 0
  487. sDecrypt = getPalindrom(str: str.substring(from: 1, to: nil))
  488. arr = Array(sDecrypt)
  489. for i in 0..<arr.count {
  490. if (isSpecialChar(ch: arr[i])) {
  491. arr[i] = getBeforecChar(ch: arr[i], inc: iRandom)
  492. } else {
  493. arr[i] = getBeforeChar(ch: arr[i], inc: iRandom)
  494. }
  495. }
  496. return String(arr)
  497. }
  498. private static func isSpecialChar(ch: Character) -> Bool {
  499. let ch = Int(ch.asciiValue ?? 0)
  500. return (ch >= IC_BB && ch <= IC_BBT_1) || (ch >= IC_BAT_1 && ch <= IC_BBT_2) || (ch >= IC_BAT_2 && ch <= IC_BBT_3) || (ch >= IC_BAT_3 && ch <= IC_BA)
  501. }
  502. private static func getPalindrom(str: String) -> String {
  503. let arr: [Character] = Array(str)
  504. var arr2: [Character] = Array(arr)
  505. for i in 0..<arr.count {
  506. arr2[i] = arr[arr.count - (i + 1)]
  507. }
  508. return String(arr2)
  509. }
  510. private static func getBeforeChar(ch: Character, inc: Int) -> Character {
  511. if icIGNORE.isEmpty {
  512. initIcIgnore()
  513. }
  514. var iAscii = ch
  515. let iAsciiBefore = iAscii
  516. if (icIGNORE.contains(Int(iAscii.asciiValue ?? 0))) {
  517. return iAscii;
  518. }
  519. if Int(iAscii.asciiValue ?? 0) > I_BA || Int(iAscii.asciiValue ?? 0) < I_BB {
  520. } else {
  521. if !icIGNORE.contains(Int(iAscii.asciiValue ?? 0)) {
  522. iAscii = Character(UnicodeScalar(Int(iAscii.asciiValue ?? 0) - inc)!)
  523. if (I_BAT_1 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= I_BAT_1) {
  524. iAscii = Character(UnicodeScalar((I_BBT_1 + 1) - (I_BAT_1 - Int(iAscii.asciiValue ?? 0)))!)
  525. }
  526. if (I_BAT_2 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= I_BAT_2) {
  527. iAscii = Character(UnicodeScalar((I_BBT_2 + 1) - (I_BAT_2 - Int(iAscii.asciiValue ?? 0)))!)
  528. }
  529. if (Int(iAscii.asciiValue ?? 0) < I_BB) {
  530. iAscii = Character(UnicodeScalar((I_BA + 1) + (Int(iAscii.asciiValue ?? 0) - I_BB))!)
  531. }
  532. }
  533. }
  534. return iAscii
  535. }
  536. private static func getBeforecChar(ch: Character, inc: Int) -> Character {
  537. var iAscii = ch
  538. let iAsciiBefore = iAscii
  539. if (Int(iAscii.asciiValue ?? 0) > IC_BA || Int(iAscii.asciiValue ?? 0) < IC_BB) {
  540. } else {
  541. iAscii = Character(UnicodeScalar(Int(iAscii.asciiValue ?? 0) - inc)!)
  542. if (Int(iAscii.asciiValue ?? 0) < IC_BB) {
  543. iAscii = Character(UnicodeScalar((IC_BA + 1) + (Int(iAscii.asciiValue ?? 0) - IC_BB))!)
  544. if (Int(iAscii.asciiValue ?? 0) < IC_BAT_3 && Int(iAscii.asciiValue ?? 0) > IC_BBT_3) {
  545. iAscii = Character(UnicodeScalar((IC_BBT_3 + 1) - (IC_BAT_3 - Int(iAscii.asciiValue ?? 0)))!)
  546. }
  547. }
  548. if (IC_BAT_3 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_3) {
  549. iAscii = Character(UnicodeScalar((IC_BBT_3 + 1) - (IC_BAT_3 - Int(iAscii.asciiValue ?? 0)))!)
  550. }
  551. if (IC_BAT_2 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_2) {
  552. iAscii = Character(UnicodeScalar((IC_BBT_2 + 1) - (IC_BAT_2 - Int(iAscii.asciiValue ?? 0)))!)
  553. }
  554. if (IC_BAT_1 > Int(iAscii.asciiValue ?? 0) && Int(iAsciiBefore.asciiValue ?? 0) >= IC_BAT_1) {
  555. iAscii = Character(UnicodeScalar((IC_BBT_1 + 1) - (IC_BAT_1 - Int(iAscii.asciiValue ?? 0)))!)
  556. }
  557. }
  558. return iAscii
  559. }
  560. public static func addBackground(view: UIView?) {
  561. do {
  562. if let view = view {
  563. DispatchQueue.global().async {
  564. DispatchQueue.main.async {
  565. let listBg = Utils.getBackgroundLight().isEmpty && Utils.getBackgroundDark().isEmpty ? Utils.getBackground() :
  566. UIApplication.shared.visibleViewController?.traitCollection.userInterfaceStyle == .dark ? Utils.getBackgroundDark() : Utils.getBackgroundLight()
  567. if listBg.isEmpty {
  568. return
  569. }
  570. var bgChoosen = ""
  571. let arrayBg = listBg.split(separator: ",")
  572. bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
  573. let urlString = Utils.getURLBase() + "get_file_from_path?img=" + bgChoosen
  574. if let cachedImage = ImageCache.shared.image(forKey: urlString) {
  575. DispatchQueue.main.async() {
  576. let backgroundImage = cachedImage
  577. let backgroundImageView = UIImageView(frame: view.bounds)
  578. backgroundImageView.image = backgroundImage
  579. backgroundImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  580. view.insertSubview(backgroundImageView, at: 0)
  581. view.sendSubviewToBack(backgroundImageView)
  582. }
  583. return
  584. }
  585. Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
  586. guard let data = data, error == nil else { return }
  587. // always update the UI from the main thread
  588. DispatchQueue.main.async() {
  589. if UIImage(data: data) != nil {
  590. let backgroundImage = UIImage(data: data)!
  591. let backgroundImageView = UIImageView(frame: view.bounds)
  592. backgroundImageView.image = backgroundImage
  593. backgroundImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  594. view.insertSubview(backgroundImageView, at: 0)
  595. view.sendSubviewToBack(backgroundImageView)
  596. ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
  597. }
  598. }
  599. }
  600. }
  601. }
  602. }
  603. } catch {
  604. }
  605. }
  606. public static func randomizeBackground(view: UIView?) {
  607. do {
  608. if let view = view {
  609. DispatchQueue.global().async {
  610. DispatchQueue.main.async {
  611. let listBg = Utils.getBackgroundLight().isEmpty && Utils.getBackgroundDark().isEmpty ? Utils.getBackground() :
  612. UIApplication.shared.visibleViewController?.traitCollection.userInterfaceStyle == .dark ? Utils.getBackgroundDark() : Utils.getBackgroundLight()
  613. if listBg.isEmpty {
  614. return
  615. }
  616. var bgChoosen = ""
  617. let arrayBg = listBg.split(separator: ",")
  618. bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
  619. let urlString = Utils.getURLBase() + "get_file_from_path?img=" + bgChoosen
  620. if let cachedImage = ImageCache.shared.image(forKey: urlString) {
  621. DispatchQueue.main.async() {
  622. let backgroundImage = cachedImage
  623. let backgroundImageView = view.subviews[0] as? UIImageView
  624. backgroundImageView?.image = backgroundImage
  625. }
  626. return
  627. }
  628. Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
  629. guard let data = data, error == nil else { return }
  630. // always update the UI from the main thread
  631. DispatchQueue.main.async() {
  632. if UIImage(data: data) != nil {
  633. let backgroundImage = UIImage(data: data)!
  634. let backgroundImageView = view.subviews[0] as? UIImageView
  635. backgroundImageView?.image = backgroundImage
  636. ImageCache.shared.save(image: UIImage(data: data)!, forKey: urlString)
  637. }
  638. }
  639. }
  640. }
  641. }
  642. }
  643. } catch {
  644. }
  645. }
  646. public static var bCheckEmulator = false
  647. public static var bCheckRooted = false
  648. public static var bPreventScreenCapture = false
  649. public static var bCheckDebug = false
  650. public static func setCheckDebugger(b: Bool) {
  651. UserDefaults.standard.set(b, forKey: "pb_check_debugging")
  652. }
  653. public static func getCheckDebugger() -> Bool {
  654. UserDefaults.standard.object(forKey: "pb_check_debugging") as? Bool ?? bCheckDebug
  655. }
  656. public static func setCheckEmulator(b: Bool) {
  657. UserDefaults.standard.set(b, forKey: "pb_check_emulator")
  658. }
  659. public static func getCheckEmulator() -> Bool {
  660. UserDefaults.standard.object(forKey: "pb_check_emulator") as? Bool ?? bCheckEmulator
  661. }
  662. public static func setCheckRooted(b: Bool) {
  663. UserDefaults.standard.set(b, forKey: "pb_check_rooted")
  664. }
  665. public static func getCheckRooted() -> Bool {
  666. UserDefaults.standard.object(forKey: "pb_check_rooted") as? Bool ?? bCheckRooted
  667. }
  668. public static func setCheckScreenCapture(b: Bool) {
  669. UserDefaults.standard.set(b, forKey: "pb_prevent_screen_capture")
  670. }
  671. public static func getCheckScreenCapture() -> Bool {
  672. UserDefaults.standard.object(forKey: "pb_prevent_screen_capture") as? Bool ?? bPreventScreenCapture
  673. }
  674. public static func setConnectionID(value: String) {
  675. UserDefaults.standard.set(value, forKey: "connection_id")
  676. }
  677. public static func getConnectionID() -> String {
  678. UserDefaults.standard.string(forKey: "connection_id") ?? ""
  679. }
  680. public static func setLimitValidTrans(value: String) {
  681. UserDefaults.standard.set(value, forKey: "pb_set_valid_trans")
  682. }
  683. public static func getLimitValidTrans() -> String {
  684. UserDefaults.standard.string(forKey: "pb_set_valid_trans") ?? "100000"
  685. }
  686. public static func setLoginMultipleFPin(value: String) {
  687. UserDefaults.standard.set(value, forKey: "pb_login_multiple_f_pin")
  688. }
  689. public static func getLoginMultipleFPin() -> String {
  690. UserDefaults.standard.string(forKey: "pb_login_multiple_f_pin") ?? ""
  691. }
  692. public static func setPrefTheme(value: String) {
  693. UserDefaults.standard.set(value, forKey: "first_pref_theme")
  694. }
  695. public static func getPrefTheme() -> String {
  696. UserDefaults.standard.string(forKey: "first_pref_theme") ?? ""
  697. }
  698. public static func setMyTheme(value: String) {
  699. UserDefaults.standard.set(value, forKey: "my_theme")
  700. }
  701. public static func getMyTheme() -> String {
  702. UserDefaults.standard.string(forKey: "my_theme") ?? ""
  703. }
  704. public static func setIsLoadThemeFromOther(value: Bool) {
  705. UserDefaults.standard.set(value, forKey: "load_theme_from_other")
  706. }
  707. public static func getIsLoadThemeFromOther() -> Bool {
  708. UserDefaults.standard.bool(forKey: "load_theme_from_other")
  709. }
  710. public static func setURLWv3(value: String) {
  711. UserDefaults.standard.set(value, forKey: "app_builder_url_webview_3")
  712. }
  713. public static func getURLWv3() -> String {
  714. UserDefaults.standard.string(forKey: "app_builder_url_webview_3") ?? ""
  715. }
  716. public static func setURLWv4(value: String) {
  717. UserDefaults.standard.set(value, forKey: "app_builder_url_webview_4")
  718. }
  719. public static func getURLWv4() -> String {
  720. UserDefaults.standard.string(forKey: "app_builder_url_webview_4") ?? ""
  721. }
  722. public static func setURLWv5(value: String) {
  723. UserDefaults.standard.set(value, forKey: "app_builder_url_webview_5")
  724. }
  725. public static func getURLWv5() -> String {
  726. UserDefaults.standard.string(forKey: "app_builder_url_webview_5") ?? ""
  727. }
  728. public static func setURLWv6(value: String) {
  729. UserDefaults.standard.set(value, forKey: "app_builder_url_webview_6")
  730. }
  731. public static func getURLWv6() -> String {
  732. UserDefaults.standard.string(forKey: "app_builder_url_webview_6") ?? ""
  733. }
  734. public static func setBackgroundTab1(value: String) {
  735. UserDefaults.standard.set(value, forKey: "app_builder_background_1")
  736. }
  737. public static func getBackgroundTab1() -> String {
  738. UserDefaults.standard.string(forKey: "app_builder_background_1") ?? ""
  739. }
  740. public static func setBackgroundTab2(value: String) {
  741. UserDefaults.standard.set(value, forKey: "app_builder_background_2")
  742. }
  743. public static func getBackgroundTab2() -> String {
  744. UserDefaults.standard.string(forKey: "app_builder_background_2") ?? ""
  745. }
  746. public static func setBackgroundTab3(value: String) {
  747. UserDefaults.standard.set(value, forKey: "app_builder_background_3")
  748. }
  749. public static func getBackgroundTab3() -> String {
  750. UserDefaults.standard.string(forKey: "app_builder_background_3") ?? ""
  751. }
  752. public static func setBackgroundTab4(value: String) {
  753. UserDefaults.standard.set(value, forKey: "app_builder_background_4")
  754. }
  755. public static func getBackgroundTab4() -> String {
  756. UserDefaults.standard.string(forKey: "app_builder_background_4") ?? ""
  757. }
  758. public static func setBackgroundTab5(value: String) {
  759. UserDefaults.standard.set(value, forKey: "app_builder_background_5")
  760. }
  761. public static func getBackgroundTab5() -> String {
  762. UserDefaults.standard.string(forKey: "app_builder_background_5") ?? ""
  763. }
  764. public static func setBackgroundTab6(value: String) {
  765. UserDefaults.standard.set(value, forKey: "app_builder_background_6")
  766. }
  767. public static func getBackgroundTab6() -> String {
  768. UserDefaults.standard.string(forKey: "app_builder_background_6") ?? ""
  769. }
  770. public static func setCpaasMode(mode: Int){
  771. UserDefaults.standard.set(mode+1, forKey: "cpaas_mode")
  772. }
  773. public static func setTab1Icon(value: String) {
  774. UserDefaults.standard.set(value, forKey: "tab1_icon")
  775. }
  776. public static func getTab1Icon() -> String {
  777. UserDefaults.standard.string(forKey: "tab1_icon") ?? ""
  778. }
  779. public static func setTab2Icon(value: String) {
  780. UserDefaults.standard.set(value, forKey: "tab2_icon")
  781. }
  782. public static func getTab2Icon() -> String {
  783. UserDefaults.standard.string(forKey: "tab2_icon") ?? ""
  784. }
  785. public static func setTab3Icon(value: String) {
  786. UserDefaults.standard.set(value, forKey: "tab3_icon")
  787. }
  788. public static func getTab3Icon() -> String {
  789. UserDefaults.standard.string(forKey: "tab3_icon") ?? ""
  790. }
  791. public static func setTab4Icon(value: String) {
  792. UserDefaults.standard.set(value, forKey: "tab4_icon")
  793. }
  794. public static func getTab4Icon() -> String {
  795. UserDefaults.standard.string(forKey: "tab4_icon") ?? ""
  796. }
  797. public static func setTab5Icon(value: String) {
  798. UserDefaults.standard.set(value, forKey: "tab5_icon")
  799. }
  800. public static func getTab5Icon() -> String {
  801. UserDefaults.standard.string(forKey: "tab5_icon") ?? ""
  802. }
  803. public static func setTab6Icon(value: String) {
  804. UserDefaults.standard.set(value, forKey: "tab6_icon")
  805. }
  806. public static func getTab6Icon() -> String {
  807. UserDefaults.standard.string(forKey: "tab6_icon") ?? ""
  808. }
  809. public static func setButtonIcon(value: String) {
  810. UserDefaults.standard.set(value, forKey: "app_builder_button_icon")
  811. }
  812. public static func getButtonIcon() -> String {
  813. UserDefaults.standard.string(forKey: "app_builder_button_icon") ?? ""
  814. }
  815. public static func setReverseTab(value: String) {
  816. UserDefaults.standard.set(value, forKey: "reverse_tab_color")
  817. }
  818. public static func getReverseTab() -> String {
  819. UserDefaults.standard.string(forKey: "reverse_tab_color") ?? "0"
  820. }
  821. public static func setIconDockSize(value: String) {
  822. UserDefaults.standard.set(value, forKey: "icon_size")
  823. }
  824. public static func getIconDockSize() -> String {
  825. UserDefaults.standard.string(forKey: "icon_size") ?? "0"
  826. }
  827. static func setDebugBC(value: [String: String]) {
  828. UserDefaults.standard.set(value, forKey: "debugBc")
  829. }
  830. static func getDebugBC() -> [String: String]? {
  831. UserDefaults.standard.object(forKey: "debugBc") as? [String : String]
  832. }
  833. }
  834. public extension UIImage {
  835. var jpeg: Data? { jpegData(compressionQuality: 1) } // QUALITY min = 0 / max = 1
  836. var png: Data? { pngData() }
  837. }
  838. public extension Data {
  839. var uiImage: UIImage? { UIImage(data: self) }
  840. }
  841. public enum ModelIphone : String {
  842. //Simulator
  843. case simulator = "simulator/sandbox",
  844. //iPod
  845. iPod1 = "iPod 1",
  846. iPod2 = "iPod 2",
  847. iPod3 = "iPod 3",
  848. iPod4 = "iPod 4",
  849. iPod5 = "iPod 5",
  850. iPod6 = "iPod 6",
  851. iPod7 = "iPod 7",
  852. //iPad
  853. iPad2 = "iPad 2",
  854. iPad3 = "iPad 3",
  855. iPad4 = "iPad 4",
  856. iPadAir = "iPad Air ",
  857. iPadAir2 = "iPad Air 2",
  858. iPadAir3 = "iPad Air 3",
  859. iPadAir4 = "iPad Air 4",
  860. iPadAir5 = "iPad Air 5",
  861. iPad5 = "iPad 5", //iPad 2017
  862. iPad6 = "iPad 6", //iPad 2018
  863. iPad7 = "iPad 7", //iPad 2019
  864. iPad8 = "iPad 8", //iPad 2020
  865. iPad9 = "iPad 9", //iPad 2021
  866. iPad10 = "iPad 10", //iPad 2022
  867. //iPad Mini
  868. iPadMini = "iPad Mini",
  869. iPadMini2 = "iPad Mini 2",
  870. iPadMini3 = "iPad Mini 3",
  871. iPadMini4 = "iPad Mini 4",
  872. iPadMini5 = "iPad Mini 5",
  873. iPadMini6 = "iPad Mini 6",
  874. //iPad Pro
  875. iPadPro9_7 = "iPad Pro 9.7\"",
  876. iPadPro10_5 = "iPad Pro 10.5\"",
  877. iPadPro11 = "iPad Pro 11\"",
  878. iPadPro2_11 = "iPad Pro 11\" 2nd gen",
  879. iPadPro3_11 = "iPad Pro 11\" 3rd gen",
  880. iPadPro12_9 = "iPad Pro 12.9\"",
  881. iPadPro2_12_9 = "iPad Pro 2 12.9\"",
  882. iPadPro3_12_9 = "iPad Pro 3 12.9\"",
  883. iPadPro4_12_9 = "iPad Pro 4 12.9\"",
  884. iPadPro5_12_9 = "iPad Pro 5 12.9\"",
  885. //iPhone
  886. iPhone4 = "iPhone 4",
  887. iPhone4S = "iPhone 4S",
  888. iPhone5 = "iPhone 5",
  889. iPhone5S = "iPhone 5S",
  890. iPhone5C = "iPhone 5C",
  891. iPhone6 = "iPhone 6",
  892. iPhone6Plus = "iPhone 6 Plus",
  893. iPhone6S = "iPhone 6S",
  894. iPhone6SPlus = "iPhone 6S Plus",
  895. iPhoneSE = "iPhone SE",
  896. iPhone7 = "iPhone 7",
  897. iPhone7Plus = "iPhone 7 Plus",
  898. iPhone8 = "iPhone 8",
  899. iPhone8Plus = "iPhone 8 Plus",
  900. iPhoneX = "iPhone X",
  901. iPhoneXS = "iPhone XS",
  902. iPhoneXSMax = "iPhone XS Max",
  903. iPhoneXR = "iPhone XR",
  904. iPhone11 = "iPhone 11",
  905. iPhone11Pro = "iPhone 11 Pro",
  906. iPhone11ProMax = "iPhone 11 Pro Max",
  907. iPhoneSE2 = "iPhone SE 2nd gen",
  908. iPhone12Mini = "iPhone 12 Mini",
  909. iPhone12 = "iPhone 12",
  910. iPhone12Pro = "iPhone 12 Pro",
  911. iPhone12ProMax = "iPhone 12 Pro Max",
  912. iPhone13Mini = "iPhone 13 Mini",
  913. iPhone13 = "iPhone 13",
  914. iPhone13Pro = "iPhone 13 Pro",
  915. iPhone13ProMax = "iPhone 13 Pro Max",
  916. iPhoneSE3 = "iPhone SE 3nd gen",
  917. iPhone14 = "iPhone 14",
  918. iPhone14Plus = "iPhone 14 Plus",
  919. iPhone14Pro = "iPhone 14 Pro",
  920. iPhone14ProMax = "iPhone 14 Pro Max",
  921. iPhone15 = "iPhone 15",
  922. iPhone15Plus = "iPhone 15 Plus",
  923. iPhone15Pro = "iPhone 15 Pro",
  924. iPhone15ProMax = "iPhone 15 Pro Max",
  925. // Apple Watch
  926. AppleWatch1 = "Apple Watch 1gen",
  927. AppleWatchS1 = "Apple Watch Series 1",
  928. AppleWatchS2 = "Apple Watch Series 2",
  929. AppleWatchS3 = "Apple Watch Series 3",
  930. AppleWatchS4 = "Apple Watch Series 4",
  931. AppleWatchS5 = "Apple Watch Series 5",
  932. AppleWatchSE = "Apple Watch Special Edition",
  933. AppleWatchS6 = "Apple Watch Series 6",
  934. AppleWatchS7 = "Apple Watch Series 7",
  935. //Apple TV
  936. AppleTV1 = "Apple TV 1gen",
  937. AppleTV2 = "Apple TV 2gen",
  938. AppleTV3 = "Apple TV 3gen",
  939. AppleTV4 = "Apple TV 4gen",
  940. AppleTV_4K = "Apple TV 4K",
  941. AppleTV2_4K = "Apple TV 4K 2gen",
  942. AppleTV3_4K = "Apple TV 4K 3gen",
  943. unrecognized = "?unrecognized?"
  944. }
  945. // #-#-#-#-#-#-#-#-#-#-#-#-#
  946. // MARK: UIDevice extensions
  947. // #-#-#-#-#-#-#-#-#-#-#-#-#
  948. public extension UIDevice {
  949. var type: ModelIphone {
  950. var systemInfo = utsname()
  951. uname(&systemInfo)
  952. let modelCode = withUnsafePointer(to: &systemInfo.machine) {
  953. $0.withMemoryRebound(to: CChar.self, capacity: 1) {
  954. ptr in String.init(validatingUTF8: ptr)
  955. }
  956. }
  957. let modelMap : [String: ModelIphone] = [
  958. //Simulator
  959. "i386" : .simulator,
  960. "x86_64" : .simulator,
  961. //iPod
  962. "iPod1,1" : .iPod1,
  963. "iPod2,1" : .iPod2,
  964. "iPod3,1" : .iPod3,
  965. "iPod4,1" : .iPod4,
  966. "iPod5,1" : .iPod5,
  967. "iPod7,1" : .iPod6,
  968. "iPod9,1" : .iPod7,
  969. //iPad
  970. "iPad2,1" : .iPad2,
  971. "iPad2,2" : .iPad2,
  972. "iPad2,3" : .iPad2,
  973. "iPad2,4" : .iPad2,
  974. "iPad3,1" : .iPad3,
  975. "iPad3,2" : .iPad3,
  976. "iPad3,3" : .iPad3,
  977. "iPad3,4" : .iPad4,
  978. "iPad3,5" : .iPad4,
  979. "iPad3,6" : .iPad4,
  980. "iPad6,11" : .iPad5, //iPad 2017
  981. "iPad6,12" : .iPad5,
  982. "iPad7,5" : .iPad6, //iPad 2018
  983. "iPad7,6" : .iPad6,
  984. "iPad7,11" : .iPad7, //iPad 2019
  985. "iPad7,12" : .iPad7,
  986. "iPad11,6" : .iPad8, //iPad 2020
  987. "iPad11,7" : .iPad8,
  988. "iPad12,1" : .iPad9, //iPad 2021
  989. "iPad12,2" : .iPad9,
  990. "iPad13,18" : .iPad10,
  991. "iPad13,19" : .iPad10,
  992. //iPad Mini
  993. "iPad2,5" : .iPadMini,
  994. "iPad2,6" : .iPadMini,
  995. "iPad2,7" : .iPadMini,
  996. "iPad4,4" : .iPadMini2,
  997. "iPad4,5" : .iPadMini2,
  998. "iPad4,6" : .iPadMini2,
  999. "iPad4,7" : .iPadMini3,
  1000. "iPad4,8" : .iPadMini3,
  1001. "iPad4,9" : .iPadMini3,
  1002. "iPad5,1" : .iPadMini4,
  1003. "iPad5,2" : .iPadMini4,
  1004. "iPad11,1" : .iPadMini5,
  1005. "iPad11,2" : .iPadMini5,
  1006. "iPad14,1" : .iPadMini6,
  1007. "iPad14,2" : .iPadMini6,
  1008. //iPad Pro
  1009. "iPad6,3" : .iPadPro9_7,
  1010. "iPad6,4" : .iPadPro9_7,
  1011. "iPad7,3" : .iPadPro10_5,
  1012. "iPad7,4" : .iPadPro10_5,
  1013. "iPad6,7" : .iPadPro12_9,
  1014. "iPad6,8" : .iPadPro12_9,
  1015. "iPad7,1" : .iPadPro2_12_9,
  1016. "iPad7,2" : .iPadPro2_12_9,
  1017. "iPad8,1" : .iPadPro11,
  1018. "iPad8,2" : .iPadPro11,
  1019. "iPad8,3" : .iPadPro11,
  1020. "iPad8,4" : .iPadPro11,
  1021. "iPad8,9" : .iPadPro2_11,
  1022. "iPad8,10" : .iPadPro2_11,
  1023. "iPad13,4" : .iPadPro3_11,
  1024. "iPad13,5" : .iPadPro3_11,
  1025. "iPad13,6" : .iPadPro3_11,
  1026. "iPad13,7" : .iPadPro3_11,
  1027. "iPad8,5" : .iPadPro3_12_9,
  1028. "iPad8,6" : .iPadPro3_12_9,
  1029. "iPad8,7" : .iPadPro3_12_9,
  1030. "iPad8,8" : .iPadPro3_12_9,
  1031. "iPad8,11" : .iPadPro4_12_9,
  1032. "iPad8,12" : .iPadPro4_12_9,
  1033. "iPad13,8" : .iPadPro5_12_9,
  1034. "iPad13,9" : .iPadPro5_12_9,
  1035. "iPad13,10" : .iPadPro5_12_9,
  1036. "iPad13,11" : .iPadPro5_12_9,
  1037. //iPad Air
  1038. "iPad4,1" : .iPadAir,
  1039. "iPad4,2" : .iPadAir,
  1040. "iPad4,3" : .iPadAir,
  1041. "iPad5,3" : .iPadAir2,
  1042. "iPad5,4" : .iPadAir2,
  1043. "iPad11,3" : .iPadAir3,
  1044. "iPad11,4" : .iPadAir3,
  1045. "iPad13,1" : .iPadAir4,
  1046. "iPad13,2" : .iPadAir4,
  1047. "iPad13,16" : .iPadAir5,
  1048. "iPad13,17" : .iPadAir5,
  1049. //iPhone
  1050. "iPhone3,1" : .iPhone4,
  1051. "iPhone3,2" : .iPhone4,
  1052. "iPhone3,3" : .iPhone4,
  1053. "iPhone4,1" : .iPhone4S,
  1054. "iPhone5,1" : .iPhone5,
  1055. "iPhone5,2" : .iPhone5,
  1056. "iPhone5,3" : .iPhone5C,
  1057. "iPhone5,4" : .iPhone5C,
  1058. "iPhone6,1" : .iPhone5S,
  1059. "iPhone6,2" : .iPhone5S,
  1060. "iPhone7,1" : .iPhone6Plus,
  1061. "iPhone7,2" : .iPhone6,
  1062. "iPhone8,1" : .iPhone6S,
  1063. "iPhone8,2" : .iPhone6SPlus,
  1064. "iPhone8,4" : .iPhoneSE,
  1065. "iPhone9,1" : .iPhone7,
  1066. "iPhone9,3" : .iPhone7,
  1067. "iPhone9,2" : .iPhone7Plus,
  1068. "iPhone9,4" : .iPhone7Plus,
  1069. "iPhone10,1" : .iPhone8,
  1070. "iPhone10,4" : .iPhone8,
  1071. "iPhone10,2" : .iPhone8Plus,
  1072. "iPhone10,5" : .iPhone8Plus,
  1073. "iPhone10,3" : .iPhoneX,
  1074. "iPhone10,6" : .iPhoneX,
  1075. "iPhone11,2" : .iPhoneXS,
  1076. "iPhone11,4" : .iPhoneXSMax,
  1077. "iPhone11,6" : .iPhoneXSMax,
  1078. "iPhone11,8" : .iPhoneXR,
  1079. "iPhone12,1" : .iPhone11,
  1080. "iPhone12,3" : .iPhone11Pro,
  1081. "iPhone12,5" : .iPhone11ProMax,
  1082. "iPhone12,8" : .iPhoneSE2,
  1083. "iPhone13,1" : .iPhone12Mini,
  1084. "iPhone13,2" : .iPhone12,
  1085. "iPhone13,3" : .iPhone12Pro,
  1086. "iPhone13,4" : .iPhone12ProMax,
  1087. "iPhone14,4" : .iPhone13Mini,
  1088. "iPhone14,5" : .iPhone13,
  1089. "iPhone14,2" : .iPhone13Pro,
  1090. "iPhone14,3" : .iPhone13ProMax,
  1091. "iPhone14,6" : .iPhoneSE3,
  1092. "iPhone14,7" : .iPhone14,
  1093. "iPhone14,8" : .iPhone14Plus,
  1094. "iPhone15,2" : .iPhone14Pro,
  1095. "iPhone15,3" : .iPhone14ProMax,
  1096. "iPhone15,4" : .iPhone15,
  1097. "iPhone15,5" : .iPhone15Plus,
  1098. "iPhone16,1" : .iPhone15Pro,
  1099. "iPhone16,2" : .iPhone15ProMax,
  1100. // Apple Watch
  1101. "Watch1,1" : .AppleWatch1,
  1102. "Watch1,2" : .AppleWatch1,
  1103. "Watch2,6" : .AppleWatchS1,
  1104. "Watch2,7" : .AppleWatchS1,
  1105. "Watch2,3" : .AppleWatchS2,
  1106. "Watch2,4" : .AppleWatchS2,
  1107. "Watch3,1" : .AppleWatchS3,
  1108. "Watch3,2" : .AppleWatchS3,
  1109. "Watch3,3" : .AppleWatchS3,
  1110. "Watch3,4" : .AppleWatchS3,
  1111. "Watch4,1" : .AppleWatchS4,
  1112. "Watch4,2" : .AppleWatchS4,
  1113. "Watch4,3" : .AppleWatchS4,
  1114. "Watch4,4" : .AppleWatchS4,
  1115. "Watch5,1" : .AppleWatchS5,
  1116. "Watch5,2" : .AppleWatchS5,
  1117. "Watch5,3" : .AppleWatchS5,
  1118. "Watch5,4" : .AppleWatchS5,
  1119. "Watch5,9" : .AppleWatchSE,
  1120. "Watch5,10" : .AppleWatchSE,
  1121. "Watch5,11" : .AppleWatchSE,
  1122. "Watch5,12" : .AppleWatchSE,
  1123. "Watch6,1" : .AppleWatchS6,
  1124. "Watch6,2" : .AppleWatchS6,
  1125. "Watch6,3" : .AppleWatchS6,
  1126. "Watch6,4" : .AppleWatchS6,
  1127. "Watch6,6" : .AppleWatchS7,
  1128. "Watch6,7" : .AppleWatchS7,
  1129. "Watch6,8" : .AppleWatchS7,
  1130. "Watch6,9" : .AppleWatchS7,
  1131. //Apple TV
  1132. "AppleTV1,1" : .AppleTV1,
  1133. "AppleTV2,1" : .AppleTV2,
  1134. "AppleTV3,1" : .AppleTV3,
  1135. "AppleTV3,2" : .AppleTV3,
  1136. "AppleTV5,3" : .AppleTV4,
  1137. "AppleTV6,2" : .AppleTV_4K,
  1138. "AppleTV11,1" : .AppleTV2_4K,
  1139. "AppleTV14,1" : .AppleTV3_4K
  1140. ]
  1141. guard let mcode = modelCode, let map = String(validatingUTF8: mcode), let model = modelMap[map] else { return ModelIphone.unrecognized }
  1142. if model == .simulator {
  1143. if let simModelCode = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] {
  1144. if let simMap = String(validatingUTF8: simModelCode), let simModel = modelMap[simMap] {
  1145. return simModel
  1146. }
  1147. }
  1148. }
  1149. return model
  1150. }
  1151. }
  1152. public class CustomNavigationController: UINavigationController {
  1153. public override func viewDidLoad() {
  1154. super.viewDidLoad()
  1155. self.view.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .black : .white
  1156. Utils.addBackground(view: self.view)
  1157. }
  1158. public override func viewDidDisappear(_ animated: Bool) {
  1159. super.viewDidDisappear(animated)
  1160. Utils.randomizeBackground(view: self.view)
  1161. }
  1162. public override init(rootViewController: UIViewController) {
  1163. super.init(rootViewController: rootViewController)
  1164. }
  1165. required init?(coder aDecoder: NSCoder) {
  1166. fatalError("init(coder:) has not been implemented")
  1167. }
  1168. }
  1169. public class DialogUnableAccess: UIViewController {
  1170. public let content = "To verify your identity for signing in on a new device, we need access to your main device. Please turn on your primary device. If it's not accessible, contact us to undergo a KYC verification process.".localized()
  1171. public override func viewDidLoad() {
  1172. super.viewDidLoad()
  1173. self.view.backgroundColor = .black.withAlphaComponent(0.5)
  1174. let container = UIView()
  1175. self.view.addSubview(container)
  1176. container.anchor(top: self.view.topAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 30, paddingLeft: 20, paddingRight: 20)
  1177. container.layer.cornerRadius = 20.0
  1178. container.clipsToBounds = true
  1179. container.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .white
  1180. let title = UILabel()
  1181. title.text = "Unable to access your primary device".localized()
  1182. title.font = .systemFont(ofSize: 14, weight: .medium)
  1183. title.numberOfLines = 0
  1184. title.textAlignment = .center
  1185. title.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1186. container.addSubview(title)
  1187. title.anchor(top: container.topAnchor, paddingTop: 15, centerX: container.centerXAnchor, width: 270)
  1188. let imageWarning = UIImageView(image: UIImage(named: "pb_security_warning", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1189. container.addSubview(imageWarning)
  1190. imageWarning.anchor(top: container.topAnchor, right: title.leftAnchor, paddingTop: 10, paddingRight: 5, width: 30, height: 30)
  1191. let imageChat = UIImageView(image: UIImage(named: "pb_startup_iconsuffix", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1192. container.addSubview(imageChat)
  1193. imageChat.anchor(top: container.topAnchor, left: title.rightAnchor, paddingTop: 10, paddingLeft: 5, width: 30, height: 30)
  1194. let contentS = UILabel()
  1195. contentS.text = content
  1196. contentS.font = .systemFont(ofSize: 12)
  1197. contentS.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1198. contentS.numberOfLines = 0
  1199. container.addSubview(contentS)
  1200. contentS.anchor(top: title.bottomAnchor, left: container.leftAnchor, right: container.rightAnchor, paddingTop: 15, paddingLeft: 15, paddingRight: 10)
  1201. let buttonKYC = UIButton(type: .custom)
  1202. let backgroundImageKYC = resizeImage(image: UIImage(named: "pb_security_kyc_center", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1203. buttonKYC.setBackgroundImage(backgroundImageKYC, for: .normal)
  1204. buttonKYC.imageView?.contentMode = .scaleAspectFill
  1205. buttonKYC.addTarget(self, action: #selector(kycTapped), for: .touchUpInside)
  1206. buttonKYC.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1207. container.addSubview(buttonKYC)
  1208. buttonKYC.anchor(top: contentS.bottomAnchor, paddingTop: 15, centerX: container.centerXAnchor, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1209. let buttonTryAgain = UIButton(type: .custom)
  1210. let backgroundImageTryAgain = resizeImage(image: UIImage(named: "pb_security_try_again", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1211. buttonTryAgain.setBackgroundImage(backgroundImageTryAgain, for: .normal)
  1212. buttonTryAgain.imageView?.contentMode = .scaleAspectFill
  1213. buttonTryAgain.addTarget(self, action: #selector(tryAgainTapped), for: .touchUpInside)
  1214. buttonTryAgain.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1215. container.addSubview(buttonTryAgain)
  1216. buttonTryAgain.anchor(top: contentS.bottomAnchor, right: buttonKYC.leftAnchor, paddingTop: 15, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1217. let buttonCancel = UIButton(type: .custom)
  1218. let backgroundImageCancel = resizeImage(image: UIImage(named: "pb_security_cancel", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1219. buttonCancel.setBackgroundImage(backgroundImageCancel, for: .normal)
  1220. buttonCancel.imageView?.contentMode = .scaleAspectFill
  1221. buttonCancel.addTarget(self, action: #selector(cancelTapped), for: .touchUpInside)
  1222. buttonCancel.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1223. container.addSubview(buttonCancel)
  1224. buttonCancel.anchor(top: contentS.bottomAnchor, left: buttonKYC.rightAnchor, paddingTop: 15, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1225. let footer = UILabel()
  1226. footer.text = "We value your security".localized()
  1227. footer.font = .systemFont(ofSize: 12)
  1228. footer.textColor = .gray
  1229. footer.numberOfLines = 0
  1230. container.addSubview(footer)
  1231. footer.anchor(top: buttonCancel.bottomAnchor, bottom: container.bottomAnchor, right: container.rightAnchor, paddingBottom: 5, paddingRight: 10)
  1232. }
  1233. @objc func kycTapped() {
  1234. //print("kycTapped")
  1235. APIS.openContactCenter()
  1236. self.dismiss(animated: true)
  1237. }
  1238. @objc func tryAgainTapped() {
  1239. //print("tryAgainTapped")
  1240. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  1241. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1242. imageView.tintColor = .white
  1243. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1244. banner.show()
  1245. return
  1246. }
  1247. Nexilis.showLoader()
  1248. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getAlertNewSignIn(brand: "\(UIDevice().type)", latitude: Utils.latitude, longitude: Utils.longitude), timeout: 30 * 1000) {
  1249. if response.isOk() {
  1250. Nexilis.hideLoader(completion: {
  1251. self.dismiss(animated: true) {
  1252. let dialog = DialogVerifyYou()
  1253. dialog.modalTransitionStyle = .crossDissolve
  1254. dialog.modalPresentationStyle = .overCurrentContext
  1255. UIApplication.shared.visibleViewController?.present(dialog, animated: true)
  1256. }
  1257. })
  1258. } else {
  1259. Nexilis.hideLoader(completion: {
  1260. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1261. imageView.tintColor = .white
  1262. let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1263. banner.show()
  1264. })
  1265. }
  1266. }
  1267. }
  1268. @objc func cancelTapped() {
  1269. Utils.setLoginMultipleFPin(value: "")
  1270. self.dismiss(animated: true)
  1271. }
  1272. }
  1273. public class DialogVerifyYou: UIViewController {
  1274. public let content = "To help keep your Account safe, We wants to make sure it's really you trying to Sign-In\n\nA secure notification containing a verification code was just sent to your main Device".localized()
  1275. let textFieldCode = UITextField()
  1276. public override func viewDidLoad() {
  1277. super.viewDidLoad()
  1278. self.view.backgroundColor = .black.withAlphaComponent(0.5)
  1279. let container = UIView()
  1280. self.view.addSubview(container)
  1281. container.anchor(top: self.view.topAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 30, paddingLeft: 20, paddingRight: 20)
  1282. container.layer.cornerRadius = 20.0
  1283. container.clipsToBounds = true
  1284. container.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .white
  1285. let title = UILabel()
  1286. title.text = "Verify it's you".localized()
  1287. title.font = .systemFont(ofSize: 14, weight: .medium)
  1288. title.numberOfLines = 0
  1289. title.textAlignment = .center
  1290. title.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1291. container.addSubview(title)
  1292. title.anchor(top: container.topAnchor, paddingTop: 15, centerX: container.centerXAnchor, maxWidth: 270)
  1293. let imageAsk = UIImageView(image: UIImage(named: "pb_security_ask", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1294. container.addSubview(imageAsk)
  1295. imageAsk.anchor(top: container.topAnchor, right: title.leftAnchor, paddingTop: 10, paddingRight: 5, width: 30, height: 30)
  1296. let imageChat = UIImageView(image: UIImage(named: "pb_startup_iconsuffix", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1297. container.addSubview(imageChat)
  1298. imageChat.anchor(top: container.topAnchor, right: container.rightAnchor, paddingTop: 10, paddingRight: 20, width: 30, height: 30)
  1299. let contentS = UILabel()
  1300. contentS.text = content
  1301. contentS.font = .systemFont(ofSize: 12)
  1302. contentS.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1303. contentS.numberOfLines = 0
  1304. container.addSubview(contentS)
  1305. contentS.anchor(top: title.bottomAnchor, left: container.leftAnchor, right: container.rightAnchor, paddingTop: 15, paddingLeft: 15, paddingRight: 10)
  1306. let containerText = UIView()
  1307. container.addSubview(containerText)
  1308. containerText.anchor(top: contentS.bottomAnchor, left: container.leftAnchor, right: container.rightAnchor, paddingTop: 10, paddingLeft: 15, paddingRight: 15, height: 40)
  1309. containerText.layer.cornerRadius = 8.0
  1310. containerText.clipsToBounds = true
  1311. containerText.layer.borderWidth = 3
  1312. containerText.layer.borderColor = UIColor.blueTextField.cgColor
  1313. let containerEnterCode = UIView()
  1314. container.addSubview(containerEnterCode)
  1315. containerEnterCode.anchor(top: contentS.bottomAnchor, left: container.leftAnchor, paddingTop: 2, paddingLeft: 30, height: 20, maxWidth: 150)
  1316. containerEnterCode.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .white
  1317. let titleEnterCode = UILabel()
  1318. containerEnterCode.addSubview(titleEnterCode)
  1319. titleEnterCode.text = "Enter Code".localized()
  1320. titleEnterCode.font = .systemFont(ofSize: 12, weight: .medium)
  1321. titleEnterCode.textColor = .blueTextField
  1322. titleEnterCode.textAlignment = .center
  1323. titleEnterCode.anchor(top: containerEnterCode.topAnchor, left: containerEnterCode.leftAnchor, bottom: containerEnterCode.bottomAnchor, right: containerEnterCode.rightAnchor, paddingLeft: 10, paddingRight: 10)
  1324. let buttonSubmit = UIButton(type: .custom)
  1325. containerText.addSubview(buttonSubmit)
  1326. buttonSubmit.anchor(top: containerText.topAnchor, bottom: containerText.bottomAnchor, right: containerText.rightAnchor, paddingTop: 5, paddingBottom: 5, paddingRight: 5, width: 100)
  1327. buttonSubmit.backgroundColor = .blueTextField
  1328. buttonSubmit.setTitle("Submit".localized(), for: .normal)
  1329. buttonSubmit.titleLabel?.font = .systemFont(ofSize: 10, weight: .medium)
  1330. buttonSubmit.layer.cornerRadius = 5.0
  1331. buttonSubmit.clipsToBounds = true
  1332. buttonSubmit.addTarget(self, action: #selector(submitTapped), for: .touchUpInside)
  1333. container.addSubview(textFieldCode)
  1334. textFieldCode.anchor(top: contentS.bottomAnchor, left: container.leftAnchor, right: buttonSubmit.leftAnchor, paddingTop: 20, paddingLeft: 25, paddingRight: 5, height: 25)
  1335. textFieldCode.keyboardType = .numberPad
  1336. let footer = UILabel()
  1337. footer.text = "We value your security".localized()
  1338. footer.font = .systemFont(ofSize: 12)
  1339. footer.textColor = .gray
  1340. footer.numberOfLines = 0
  1341. container.addSubview(footer)
  1342. footer.anchor(top: containerText.bottomAnchor, bottom: container.bottomAnchor, right: container.rightAnchor, paddingTop: 8, paddingBottom: 5, paddingRight: 10)
  1343. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissView))
  1344. tapGesture.cancelsTouchesInView = false
  1345. self.view.addGestureRecognizer(tapGesture)
  1346. }
  1347. @objc func submitTapped() {
  1348. //print("submitTapped")
  1349. if textFieldCode.text!.isEmpty {
  1350. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1351. imageView.tintColor = .white
  1352. let banner = FloatingNotificationBanner(title: "Code can't be empty".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1353. banner.show()
  1354. return
  1355. }
  1356. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  1357. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1358. imageView.tintColor = .white
  1359. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1360. banner.show()
  1361. return
  1362. }
  1363. Nexilis.showLoader()
  1364. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getShieldSecurityValidateToken(token: textFieldCode.text!), timeout: 30 * 1000) {
  1365. if response.isOk() {
  1366. Nexilis.hideLoader(completion: {
  1367. let fPin = response.getBody(key: CoreMessage_TMessageKey.F_PIN, default_value: "")
  1368. let device_id = response.getBody(key: CoreMessage_TMessageKey.IMEI, default_value: "")
  1369. self.deleteAllRecordDatabase()
  1370. if(!fPin.isEmpty) {
  1371. // Nexilis.changeUser(f_pin: device_id)
  1372. Utils.setLoginMultipleFPin(value: "")
  1373. UserDefaults.standard.setValue(device_id, forKey: "device_id")
  1374. Utils.setProfile(value: true)
  1375. UserDefaults.standard.synchronize()
  1376. // pos registration
  1377. _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: fPin))
  1378. DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
  1379. Nexilis.hideLoader(completion: {
  1380. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  1381. imageView.tintColor = .white
  1382. let banner = FloatingNotificationBanner(title: "Successfully Sign-In".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
  1383. banner.show()
  1384. if Nexilis.showFB {
  1385. Nexilis.floatingButton.removeFromSuperview()
  1386. Nexilis.floatingButton = FloatingButton()
  1387. let viewController = (UIApplication.shared.windows.first?.rootViewController)!
  1388. Nexilis.addFB(viewController: viewController, fromMAB: true)
  1389. }
  1390. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "onRefreshWebView"), object: nil, userInfo: nil)
  1391. self.dismiss(animated: true)
  1392. })
  1393. })
  1394. }
  1395. })
  1396. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "4t" {
  1397. Nexilis.hideLoader(completion: {
  1398. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1399. imageView.tintColor = .white
  1400. let banner = FloatingNotificationBanner(title: "Invalid Code".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1401. banner.show()
  1402. self.dismiss(animated: true)
  1403. })
  1404. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "3t" {
  1405. Nexilis.hideLoader(completion: {
  1406. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1407. imageView.tintColor = .white
  1408. let banner = FloatingNotificationBanner(title: "Expired Code".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1409. banner.show()
  1410. self.dismiss(animated: true)
  1411. })
  1412. } else if response.getBody(key: CoreMessage_TMessageKey.ERRCOD, default_value: "99") == "4u" {
  1413. Nexilis.hideLoader(completion: {
  1414. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1415. imageView.tintColor = .white
  1416. let banner = FloatingNotificationBanner(title: "You have been blocked".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1417. banner.show()
  1418. self.dismiss(animated: true)
  1419. })
  1420. } else {
  1421. Nexilis.hideLoader(completion: {
  1422. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1423. imageView.tintColor = .white
  1424. let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1425. banner.show()
  1426. })
  1427. }
  1428. }
  1429. }
  1430. @objc func dismissView() {
  1431. if textFieldCode.isFirstResponder {
  1432. textFieldCode.resignFirstResponder()
  1433. } else {
  1434. self.dismiss(animated: true)
  1435. }
  1436. }
  1437. }
  1438. public class DialogSignIn: UIViewController {
  1439. public var valueDevice = "Galaxy S21 Ultra 5G"
  1440. public var valueTime = "14:02"
  1441. public var valueLocation = "Surakarta, Central Java"
  1442. public var valueToken = ""
  1443. public var valueUser = ""
  1444. public override func viewDidLoad() {
  1445. super.viewDidLoad()
  1446. self.view.backgroundColor = .black.withAlphaComponent(0.5)
  1447. let container = UIView()
  1448. self.view.addSubview(container)
  1449. container.anchor(top: self.view.topAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 30, paddingLeft: 20, paddingRight: 20)
  1450. container.layer.cornerRadius = 20.0
  1451. container.clipsToBounds = true
  1452. container.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .white
  1453. let title = UILabel()
  1454. title.text = "New Sign-In Detected".localized()
  1455. title.font = .systemFont(ofSize: 14, weight: .medium)
  1456. title.numberOfLines = 0
  1457. title.textAlignment = .center
  1458. title.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1459. container.addSubview(title)
  1460. title.anchor(top: container.topAnchor, paddingTop: 15, centerX: container.centerXAnchor, maxWidth: 270)
  1461. let imageWarning = UIImageView(image: UIImage(named: "pb_security_warning", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1462. container.addSubview(imageWarning)
  1463. imageWarning.anchor(top: container.topAnchor, right: title.leftAnchor, paddingTop: 10, paddingRight: 5, width: 30, height: 30)
  1464. let imageChat = UIImageView(image: UIImage(named: "pb_startup_iconsuffix", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1465. container.addSubview(imageChat)
  1466. imageChat.anchor(top: container.topAnchor, right: container.rightAnchor, paddingTop: 10, paddingRight: 20, width: 30, height: 30)
  1467. let lang = UserDefaults.standard.string(forKey: "i18n_language")
  1468. let sContent1 = "We detected a new Sign-In to your Account".localized()
  1469. let sContent2 = "Device".localized()
  1470. let sContent3 = "Time".localized()
  1471. let sContent4 = "Location".localized()
  1472. let sContent5 = "Your Account is at risk if this wasn't you.".localized()
  1473. let fullString = sContent1 + "\n\u{2022}\u{00a0}\u{00a0}" + sContent2 + String(repeating: "\u{00a0}", count: (lang == "id" ? 6 : 10)) + ": " + valueDevice + "\n\u{2022}\u{00a0}\u{00a0}" + sContent3 + String(repeating: "\u{00a0}", count: 13) + ": " + valueTime + "\n\u{2022}\u{00a0}\u{00a0}" + sContent4 + String(repeating: "\u{00a0}", count: (lang == "id" ? 13 : 6)) + ": " + valueLocation + "\n\n" + sContent5;
  1474. let contentFull = NSMutableAttributedString(string: fullString)
  1475. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 12)], range: NSRange(location: 0, length: fullString.count))
  1476. if let range = fullString.range(of: valueDevice) {
  1477. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1478. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 12, weight: .medium)], range: NSRange(location: index, length: valueDevice.count))
  1479. }
  1480. if let range = fullString.range(of: valueTime) {
  1481. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1482. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 12, weight: .medium)], range: NSRange(location: index, length: valueTime.count))
  1483. }
  1484. if let range = fullString.range(of: valueLocation) {
  1485. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1486. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 12, weight: .medium)], range: NSRange(location: index, length: valueLocation.count))
  1487. }
  1488. let contentS = UILabel()
  1489. contentS.attributedText = contentFull
  1490. contentS.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1491. contentS.numberOfLines = 0
  1492. container.addSubview(contentS)
  1493. contentS.anchor(top: title.bottomAnchor, left: container.leftAnchor, right: container.rightAnchor, paddingTop: 15, paddingLeft: 15, paddingRight: 10)
  1494. let buttonCC = UIButton(type: .custom)
  1495. let backgroundImageKYC = resizeImage(image: UIImage(named: "pb_startup_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1496. buttonCC.setBackgroundImage(backgroundImageKYC, for: .normal)
  1497. buttonCC.imageView?.contentMode = .scaleAspectFill
  1498. buttonCC.addTarget(self, action: #selector(ccTapped), for: .touchUpInside)
  1499. buttonCC.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1500. container.addSubview(buttonCC)
  1501. buttonCC.anchor(top: contentS.bottomAnchor, paddingTop: 10, centerX: container.centerXAnchor, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1502. let buttonVerify = UIButton(type: .custom)
  1503. let backgroundImageTryAgain = resizeImage(image: UIImage(named: "pb_security_verify_device", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1504. buttonVerify.setBackgroundImage(backgroundImageTryAgain, for: .normal)
  1505. buttonVerify.imageView?.contentMode = .scaleAspectFill
  1506. buttonVerify.addTarget(self, action: #selector(verifyTapped), for: .touchUpInside)
  1507. buttonVerify.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1508. container.addSubview(buttonVerify)
  1509. buttonVerify.anchor(top: contentS.bottomAnchor, right: buttonCC.leftAnchor, paddingTop: 10, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1510. let buttonBlock = UIButton(type: .custom)
  1511. let backgroundImageCancel = resizeImage(image: UIImage(named: "pb_security_block_device", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1512. buttonBlock.setBackgroundImage(backgroundImageCancel, for: .normal)
  1513. buttonBlock.imageView?.contentMode = .scaleAspectFill
  1514. buttonBlock.addTarget(self, action: #selector(blockTapped), for: .touchUpInside)
  1515. buttonBlock.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1516. container.addSubview(buttonBlock)
  1517. buttonBlock.anchor(top: contentS.bottomAnchor, left: buttonCC.rightAnchor, paddingTop: 10, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1518. let footer = UILabel()
  1519. footer.text = "We value your security".localized()
  1520. footer.font = .systemFont(ofSize: 12)
  1521. footer.textColor = .gray
  1522. footer.numberOfLines = 0
  1523. container.addSubview(footer)
  1524. footer.anchor(top: buttonBlock.bottomAnchor, bottom: container.bottomAnchor, right: container.rightAnchor, paddingBottom: 5, paddingRight: 10)
  1525. }
  1526. @objc func ccTapped() {
  1527. //print("ccTapped")
  1528. APIS.openContactCenter()
  1529. self.dismiss(animated: true)
  1530. }
  1531. @objc func verifyTapped() {
  1532. //print("verifyTapped")
  1533. self.dismiss(animated: true) {
  1534. let dialog = DialogVerificationCode()
  1535. dialog.valueDevice = self.valueDevice
  1536. dialog.valueCode = self.valueToken
  1537. dialog.modalTransitionStyle = .crossDissolve
  1538. dialog.modalPresentationStyle = .overCurrentContext
  1539. UIApplication.shared.visibleViewController?.present(dialog, animated: true)
  1540. }
  1541. }
  1542. @objc func blockTapped() {
  1543. //print("blockTapped")
  1544. if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
  1545. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1546. imageView.tintColor = .white
  1547. let banner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1548. banner.show()
  1549. return
  1550. }
  1551. Nexilis.showLoader()
  1552. if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.getBlockAccess(userId: valueUser), timeout: 30 * 1000) {
  1553. if response.isOk() {
  1554. Nexilis.hideLoader(completion: {
  1555. let imageView = UIImageView(image: UIImage(systemName: "info.circle"))
  1556. imageView.tintColor = .white
  1557. let banner = FloatingNotificationBanner(title: "The other device has been blocked".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .info, colors: nil, iconPosition: .center)
  1558. banner.show()
  1559. self.dismiss(animated: true)
  1560. })
  1561. } else {
  1562. Nexilis.hideLoader(completion: {
  1563. let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
  1564. imageView.tintColor = .white
  1565. let banner = FloatingNotificationBanner(title: "Unable to access servers. Try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
  1566. banner.show()
  1567. })
  1568. }
  1569. }
  1570. }
  1571. }
  1572. public class DialogVerificationCode: UIViewController {
  1573. public var valueDevice = "Galaxy S21 Ultra 5G"
  1574. public var valueAccount = "1001001234."
  1575. public var valueCode = "900214"
  1576. public override func viewDidLoad() {
  1577. super.viewDidLoad()
  1578. self.view.backgroundColor = .black.withAlphaComponent(0.5)
  1579. let container = UIView()
  1580. self.view.addSubview(container)
  1581. container.anchor(top: self.view.topAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 30, paddingLeft: 20, paddingRight: 20)
  1582. container.layer.cornerRadius = 20.0
  1583. container.clipsToBounds = true
  1584. container.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .white
  1585. let title = UILabel()
  1586. title.text = "Nexilis Verification Code".localized()
  1587. title.font = .systemFont(ofSize: 14, weight: .medium)
  1588. title.numberOfLines = 0
  1589. title.textAlignment = .center
  1590. title.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1591. container.addSubview(title)
  1592. title.anchor(top: container.topAnchor, paddingTop: 15, centerX: container.centerXAnchor, maxWidth: 270)
  1593. let imageInfo = UIImageView(image: UIImage(named: "pb_security_information", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1594. container.addSubview(imageInfo)
  1595. imageInfo.anchor(top: container.topAnchor, right: title.leftAnchor, paddingTop: 10, paddingRight: 5, width: 30, height: 30)
  1596. let imageMail = UIImageView(image: UIImage(named: "pb_security_message", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1597. container.addSubview(imageMail)
  1598. imageMail.anchor(top: container.topAnchor, right: container.rightAnchor, paddingTop: 10, paddingRight: 20, width: 30, height: 30)
  1599. let sContent1 = "We received a request to verify the Sign-In from".localized()
  1600. let sContent2 = "to your Account".localized()
  1601. let sContent3 = "Your Nexilis verification code is".localized()
  1602. let sContent4 = "(do not forward or give this code to anyone)".localized()
  1603. let sContent5 = "If you did not request this code, it is possible that someone else is trying to access the Account.".localized()
  1604. let fullString = sContent1 + " " + valueDevice + " " + sContent2 + " " + valueAccount + " " + sContent3 + ":\n\n" + valueCode + " " + sContent4 + "\n\n" + sContent5;
  1605. let contentFull = NSMutableAttributedString(string: fullString)
  1606. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 12), .foregroundColor: (self.traitCollection.userInterfaceStyle == .dark ? UIColor.white : UIColor.black)], range: NSRange(location: 0, length: fullString.count))
  1607. if let range = fullString.range(of: valueDevice) {
  1608. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1609. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 12, weight: .medium)], range: NSRange(location: index, length: valueDevice.count))
  1610. }
  1611. if let range = fullString.range(of: valueAccount) {
  1612. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1613. contentFull.addAttributes([.foregroundColor: UIColor.blueTextField], range: NSRange(location: index, length: valueAccount.count))
  1614. }
  1615. if let range = fullString.range(of: valueCode) {
  1616. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1617. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 18, weight: .medium)], range: NSRange(location: index, length: valueCode.count))
  1618. }
  1619. if let range = fullString.range(of: sContent4) {
  1620. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1621. contentFull.addAttributes([.foregroundColor: UIColor.systemRed], range: NSRange(location: index, length: sContent4.count))
  1622. }
  1623. let contentS = UILabel()
  1624. contentS.attributedText = contentFull
  1625. contentS.numberOfLines = 0
  1626. container.addSubview(contentS)
  1627. contentS.anchor(top: title.bottomAnchor, left: container.leftAnchor, right: container.rightAnchor, paddingTop: 15, paddingLeft: 15, paddingRight: 10)
  1628. let footer = UILabel()
  1629. footer.text = "We value your security".localized()
  1630. footer.font = .systemFont(ofSize: 12)
  1631. footer.textColor = .gray
  1632. footer.numberOfLines = 0
  1633. container.addSubview(footer)
  1634. footer.anchor(top: contentS.bottomAnchor, bottom: container.bottomAnchor, right: container.rightAnchor, paddingTop: 10, paddingBottom: 5, paddingRight: 10)
  1635. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissView))
  1636. tapGesture.cancelsTouchesInView = false
  1637. self.view.addGestureRecognizer(tapGesture)
  1638. }
  1639. @objc func dismissView() {
  1640. self.dismiss(animated: true)
  1641. }
  1642. }
  1643. public class DialogSecurityShield: UIViewController {
  1644. public override func viewDidLoad() {
  1645. super.viewDidLoad()
  1646. self.view.backgroundColor = .black.withAlphaComponent(0.5)
  1647. let container = UIView()
  1648. self.view.addSubview(container)
  1649. container.anchor(top: self.view.topAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 30, paddingLeft: 20, paddingRight: 20)
  1650. container.layer.cornerRadius = 20.0
  1651. container.clipsToBounds = true
  1652. container.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .white
  1653. let title = UILabel()
  1654. title.text = "Your Account is Protected".localized()
  1655. title.font = .systemFont(ofSize: 14, weight: .medium)
  1656. title.numberOfLines = 0
  1657. title.textAlignment = .center
  1658. title.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1659. container.addSubview(title)
  1660. title.anchor(top: container.topAnchor, paddingTop: 15, centerX: container.centerXAnchor, maxWidth: 270)
  1661. let imageWarning = UIImageView(image: UIImage(named: "pb_security_warning_green", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1662. container.addSubview(imageWarning)
  1663. imageWarning.anchor(top: container.topAnchor, right: title.leftAnchor, paddingTop: 10, paddingRight: 5, width: 30, height: 30)
  1664. let imageChat = UIImageView(image: UIImage(named: "pb_startup_iconsuffix", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1665. container.addSubview(imageChat)
  1666. imageChat.anchor(top: container.topAnchor, right: container.rightAnchor, paddingTop: 10, paddingRight: 20, width: 30, height: 30)
  1667. let sContent1 = "Security Shield has been activated for your Peace of Mind...".localized()
  1668. let sContent2 = "Account & Transaction Protection".localized()
  1669. let sContent3 = "Early Threat Detection".localized()
  1670. let sContent4 = "Emergency Data Control".localized()
  1671. let sContent5 = "Please feel free to contact us for more information.".localized()
  1672. let fullString = sContent1 + "\n\u{2022}" + String(repeating: "\u{00a0}", count: 2) + sContent2 + "\n\u{2022}" + String(repeating: "\u{00a0}", count: 2) + sContent3 + "\n\u{2022}" + String(repeating: "\u{00a0}", count: 2) + sContent4 + "\n" + sContent5;
  1673. let contentS = UILabel()
  1674. contentS.text = fullString
  1675. contentS.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1676. contentS.numberOfLines = 0
  1677. contentS.font = .systemFont(ofSize: 12)
  1678. container.addSubview(contentS)
  1679. contentS.anchor(top: title.bottomAnchor, left: container.leftAnchor, right: container.rightAnchor, paddingTop: 15, paddingLeft: 15, paddingRight: 10)
  1680. let buttonCC = UIButton(type: .custom)
  1681. let backgroundImageKYC = resizeImage(image: UIImage(named: "pb_startup_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1682. buttonCC.setBackgroundImage(backgroundImageKYC, for: .normal)
  1683. buttonCC.imageView?.contentMode = .scaleAspectFill
  1684. buttonCC.addTarget(self, action: #selector(ccTapped), for: .touchUpInside)
  1685. buttonCC.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1686. container.addSubview(buttonCC)
  1687. buttonCC.anchor(top: contentS.bottomAnchor, paddingTop: 10, centerX: container.centerXAnchor, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1688. let buttonActive = UIButton(type: .custom)
  1689. let backgroundImageTryAgain = resizeImage(image: UIImage(named: "pb_startup_activate", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1690. buttonActive.setBackgroundImage(backgroundImageTryAgain, for: .normal)
  1691. buttonActive.imageView?.contentMode = .scaleAspectFill
  1692. buttonActive.addTarget(self, action: #selector(activateTapped), for: .touchUpInside)
  1693. buttonActive.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1694. container.addSubview(buttonActive)
  1695. buttonActive.anchor(top: contentS.bottomAnchor, right: buttonCC.leftAnchor, paddingTop: 10, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1696. let buttonDeactive = UIButton(type: .custom)
  1697. let backgroundImageCancel = resizeImage(image: UIImage(named: "pb_startup_deactivate", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1698. buttonDeactive.setBackgroundImage(backgroundImageCancel, for: .normal)
  1699. buttonDeactive.imageView?.contentMode = .scaleAspectFill
  1700. buttonDeactive.addTarget(self, action: #selector(deactiveTapped), for: .touchUpInside)
  1701. buttonDeactive.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1702. container.addSubview(buttonDeactive)
  1703. buttonDeactive.anchor(top: contentS.bottomAnchor, left: buttonCC.rightAnchor, paddingTop: 10, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1704. let footer = UILabel()
  1705. footer.text = "We value your security".localized()
  1706. footer.font = .systemFont(ofSize: 12)
  1707. footer.textColor = .gray
  1708. footer.numberOfLines = 0
  1709. container.addSubview(footer)
  1710. footer.anchor(top: buttonDeactive.bottomAnchor, bottom: container.bottomAnchor, right: container.rightAnchor, paddingBottom: 5, paddingRight: 10)
  1711. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissView))
  1712. tapGesture.cancelsTouchesInView = false
  1713. self.view.addGestureRecognizer(tapGesture)
  1714. }
  1715. @objc func ccTapped() {
  1716. //print("ccTapped")
  1717. APIS.openContactCenter()
  1718. self.dismiss(animated: true)
  1719. }
  1720. @objc func activateTapped() {
  1721. //print("activateTapped")
  1722. self.dismiss(animated: true)
  1723. }
  1724. @objc func deactiveTapped() {
  1725. //print("deactiveTapped")
  1726. self.dismiss(animated: true)
  1727. }
  1728. @objc func dismissView() {
  1729. self.dismiss(animated: true)
  1730. }
  1731. }
  1732. public class DialogTransactionApproval: UIViewController {
  1733. public var valueLink = "https://hdtrack.com"
  1734. public var valueAmount = "$142.90"
  1735. public var packetId = ""
  1736. public override func viewDidLoad() {
  1737. super.viewDidLoad()
  1738. self.view.backgroundColor = .black.withAlphaComponent(0.5)
  1739. let container = UIView()
  1740. self.view.addSubview(container)
  1741. container.anchor(top: self.view.topAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 30, paddingLeft: 20, paddingRight: 20)
  1742. container.layer.cornerRadius = 20.0
  1743. container.clipsToBounds = true
  1744. container.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .white
  1745. let title = UILabel()
  1746. title.text = "Transaction Approval Request".localized()
  1747. title.font = .systemFont(ofSize: 14, weight: .medium)
  1748. title.numberOfLines = 0
  1749. title.textAlignment = .center
  1750. title.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  1751. container.addSubview(title)
  1752. title.anchor(top: container.topAnchor, paddingTop: 15, centerX: container.centerXAnchor, maxWidth: 270)
  1753. let imageWarning = UIImageView(image: UIImage(named: "pb_security_warning", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1754. container.addSubview(imageWarning)
  1755. imageWarning.anchor(top: container.topAnchor, right: title.leftAnchor, paddingTop: 10, paddingRight: 5, width: 30, height: 30)
  1756. let imageChat = UIImageView(image: UIImage(named: "pb_startup_iconsuffix", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!)
  1757. container.addSubview(imageChat)
  1758. imageChat.anchor(top: container.topAnchor, right: container.rightAnchor, paddingTop: 10, paddingRight: 20, width: 30, height: 30)
  1759. let sContent1 = "We have detected a".localized()
  1760. let sContent1a = "Rp."
  1761. let sContent2 = "transaction using credit card no. XXXX-XXXX-XXXX-1234 on".localized()
  1762. let sContent3 = "Before processing your payment, kindly verify and confirm the transaction details.".localized()
  1763. let fullString = sContent1 + " " + sContent1a + " " + formatText(valueAmount) + " " + sContent2 + " " + valueLink + ".\n\n" + sContent3
  1764. let contentFull = NSMutableAttributedString(string: fullString)
  1765. contentFull.addAttributes([.font: UIFont.systemFont(ofSize: 12), .foregroundColor: (self.traitCollection.userInterfaceStyle == .dark ? UIColor.white : UIColor.black)], range: NSRange(location: 0, length: fullString.count))
  1766. if let range = fullString.range(of: valueLink) {
  1767. let index = fullString.distance(from: fullString.startIndex, to: range.lowerBound)
  1768. contentFull.addAttributes([.foregroundColor: UIColor.red, .underlineStyle: NSUnderlineStyle.single.rawValue, .link: URL(string: valueLink)!], range: NSRange(location: index, length: valueLink.count))
  1769. }
  1770. let contentS = UILabel()
  1771. contentS.attributedText = contentFull
  1772. contentS.numberOfLines = 0
  1773. container.addSubview(contentS)
  1774. contentS.anchor(top: title.bottomAnchor, left: container.leftAnchor, right: container.rightAnchor, paddingTop: 15, paddingLeft: 15, paddingRight: 10)
  1775. contentS.isUserInteractionEnabled = true
  1776. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(labelTapped))
  1777. contentS.addGestureRecognizer(tapGesture)
  1778. let buttonCC = UIButton(type: .custom)
  1779. let backgroundImageKYC = resizeImage(image: UIImage(named: "pb_startup_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1780. buttonCC.setBackgroundImage(backgroundImageKYC, for: .normal)
  1781. buttonCC.imageView?.contentMode = .scaleAspectFill
  1782. buttonCC.addTarget(self, action: #selector(ccTapped), for: .touchUpInside)
  1783. buttonCC.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1784. container.addSubview(buttonCC)
  1785. buttonCC.anchor(top: contentS.bottomAnchor, paddingTop: 10, centerX: container.centerXAnchor, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1786. let buttonApprove = UIButton(type: .custom)
  1787. let backgroundImageTryAgain = resizeImage(image: UIImage(named: "pb_security_approve", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1788. buttonApprove.setBackgroundImage(backgroundImageTryAgain, for: .normal)
  1789. buttonApprove.imageView?.contentMode = .scaleAspectFill
  1790. buttonApprove.addTarget(self, action: #selector(approveTapped), for: .touchUpInside)
  1791. buttonApprove.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1792. container.addSubview(buttonApprove)
  1793. buttonApprove.anchor(top: contentS.bottomAnchor, right: buttonCC.leftAnchor, paddingTop: 10, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1794. let buttonReject = UIButton(type: .custom)
  1795. let backgroundImageCancel = resizeImage(image: UIImage(named: "pb_security_reject", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: UIScreen.main.bounds.width / 3 - 20, height: 35))
  1796. buttonReject.setBackgroundImage(backgroundImageCancel, for: .normal)
  1797. buttonReject.imageView?.contentMode = .scaleAspectFill
  1798. buttonReject.addTarget(self, action: #selector(rejectTapped), for: .touchUpInside)
  1799. buttonReject.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  1800. container.addSubview(buttonReject)
  1801. buttonReject.anchor(top: contentS.bottomAnchor, left: buttonCC.rightAnchor, paddingTop: 10, width: UIScreen.main.bounds.width / 3 - 20, height: 35)
  1802. let footer = UILabel()
  1803. footer.text = "We value your security".localized()
  1804. footer.font = .systemFont(ofSize: 12)
  1805. footer.textColor = .gray
  1806. footer.numberOfLines = 0
  1807. container.addSubview(footer)
  1808. footer.anchor(top: buttonReject.bottomAnchor, bottom: container.bottomAnchor, right: container.rightAnchor, paddingBottom: 5, paddingRight: 10)
  1809. }
  1810. @objc func ccTapped() {
  1811. //print("ccTapped")
  1812. APIS.openContactCenter()
  1813. self.dismiss(animated: true)
  1814. }
  1815. @objc func approveTapped() {
  1816. //print("approveTapped")
  1817. // _ = Nexilis.responseString(packetId: packetId, message: "00", timeout: 3000)
  1818. self.dismiss(animated: true)
  1819. }
  1820. @objc func rejectTapped() {
  1821. //print("rejectTapped")
  1822. // _ = Nexilis.responseString(packetId: packetId, message: "00", timeout: 3000)
  1823. self.dismiss(animated: true)
  1824. }
  1825. @objc func labelTapped(sender: UITapGestureRecognizer) {
  1826. guard let url = URL(string: valueLink) else { return }
  1827. UIApplication.shared.open(url)
  1828. }
  1829. func formatText(_ s: String) -> String {
  1830. let text = s
  1831. if text.isEmpty { return "" }
  1832. let cleanString = text.replacingOccurrences(of: "[^\\d]", with: "", options: .regularExpression)
  1833. let formatter = NumberFormatter()
  1834. formatter.numberStyle = .decimal
  1835. formatter.locale = Locale(identifier: "en_US")
  1836. let formattedString = formatter.string(from: NSNumber(value: Int(cleanString)!)) ?? ""
  1837. return formattedString
  1838. }
  1839. }
  1840. public class ValidationTransactionLimit: UIViewController, UITextFieldDelegate {
  1841. var textField = UITextField()
  1842. var formatter = NumberFormatter()
  1843. public override func viewDidLoad() {
  1844. super.viewDidLoad()
  1845. navigationController?.navigationBar.tintColor = .white
  1846. navigationController?.navigationBar.topItem?.backButtonTitle = "Back".localized()
  1847. let title = UILabel()
  1848. title.text = "Set a transation validation amount".localized()
  1849. title.font = .systemFont(ofSize: 18, weight: .medium)
  1850. title.numberOfLines = 0
  1851. title.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .mainColor
  1852. self.view.addSubview(title)
  1853. title.anchor(top: self.view.safeAreaLayoutGuide.topAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 10, paddingLeft: 20, paddingRight: 20)
  1854. let content = UILabel()
  1855. content.text = "Any transaction over this amount will display an alert and require you to accept the alert to validate before proceeding with the transaction".localized()
  1856. content.font = .systemFont(ofSize: 14)
  1857. content.numberOfLines = 0
  1858. content.textColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .mainColor
  1859. self.view.addSubview(content)
  1860. content.anchor(top: title.bottomAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 5, paddingLeft: 20, paddingRight: 20)
  1861. self.view.addSubview(textField)
  1862. textField.anchor(top: content.bottomAnchor, left: self.view.leftAnchor, right: self.view.rightAnchor, paddingTop: 5, paddingLeft: 20, paddingRight: 20, height: 40)
  1863. textField.textAlignment = .center
  1864. textField.keyboardType = .numberPad
  1865. textField.layer.borderWidth = 1
  1866. textField.layer.borderColor = UIColor.gray.cgColor
  1867. textField.layer.cornerRadius = 10
  1868. textField.clipsToBounds = true
  1869. textField.text = formatText(Utils.getLimitValidTrans())
  1870. textField.delegate = self
  1871. }
  1872. public override func viewDidAppear(_ animated: Bool) {
  1873. navigationController?.navigationBar.topItem?.backButtonTitle = "Back".localized()
  1874. navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Submit".localized(), style: .plain, target: self, action: #selector(submit))
  1875. let attributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16.0), NSAttributedString.Key.foregroundColor: UIColor.white]
  1876. let navBarAppearance = UINavigationBarAppearance()
  1877. navBarAppearance.configureWithOpaqueBackground()
  1878. navBarAppearance.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : UIColor.mainColor
  1879. navBarAppearance.titleTextAttributes = attributes
  1880. navigationController?.navigationBar.standardAppearance = navBarAppearance
  1881. navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
  1882. self.navigationController?.navigationBar.topItem?.title = "Validation Transaction Limit".localized()
  1883. self.navigationController?.navigationBar.setNeedsLayout()
  1884. self.title = "Validation Transaction Limit".localized()
  1885. }
  1886. @objc func submit() {
  1887. if !textField.text!.isEmpty {
  1888. var text = textField.text!
  1889. text = text.replacingOccurrences(of: ",", with: "", options: .regularExpression)
  1890. Utils.setLimitValidTrans(value: text)
  1891. let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
  1892. imageView.tintColor = .white
  1893. let banner = FloatingNotificationBanner(title: "Successfully changed".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
  1894. banner.show()
  1895. self.navigationController?.popViewController(animated: true)
  1896. }
  1897. }
  1898. public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  1899. guard string != "\n" else {
  1900. return true
  1901. }
  1902. let currentText = textField.text ?? ""
  1903. let newText = (currentText as NSString).replacingCharacters(in: range, with: string)
  1904. let formattedNumber = formatText(newText)
  1905. if formattedNumber.count <= 13 {
  1906. textField.text = formattedNumber
  1907. }
  1908. return false
  1909. }
  1910. func formatText(_ s: String) -> String {
  1911. let text = s
  1912. if text.isEmpty { return "" }
  1913. let cleanString = text.replacingOccurrences(of: "[^\\d]", with: "", options: .regularExpression)
  1914. let formatter = NumberFormatter()
  1915. formatter.numberStyle = .decimal
  1916. formatter.locale = Locale(identifier: "en_US")
  1917. let formattedString = formatter.string(from: NSNumber(value: Int(cleanString)!)) ?? ""
  1918. return formattedString
  1919. }
  1920. }
  1921. class LocationManager: NSObject, CLLocationManagerDelegate {
  1922. private var locationManager = CLLocationManager()
  1923. override init() {
  1924. super.init()
  1925. self.locationManager.delegate = self
  1926. self.locationManager.requestWhenInUseAuthorization()
  1927. self.locationManager.startUpdatingLocation()
  1928. if let location = locationManager.location {
  1929. let latitude = location.coordinate.latitude
  1930. let longitude = location.coordinate.longitude
  1931. Utils.latitude = "\(latitude)"
  1932. Utils.longitude = "\(longitude)"
  1933. }
  1934. }
  1935. func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  1936. //print("didUpdateLocations")
  1937. if let location = locations.last {
  1938. let latitude = location.coordinate.latitude
  1939. let longitude = location.coordinate.longitude
  1940. Utils.latitude = "\(latitude)"
  1941. Utils.longitude = "\(longitude)"
  1942. }
  1943. }
  1944. func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
  1945. //print("Failed to find user's location: \(error.localizedDescription)")
  1946. }
  1947. }