Utils.swift 131 KB

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