Utils.swift 121 KB

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