Utils.swift 122 KB

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