Utils.swift 119 KB

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