Utils.swift 123 KB

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