Utils.swift 131 KB

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