Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.48 KB | None | 0 0
  1. //
  2. // UserService.swift
  3. // isamtech
  4. //
  5. // Created by Diego Robles on 3/16/16.
  6. // Copyright © 2016 Diego Robles. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10. import Alamofire
  11. import SwiftyJSON
  12.  
  13. class UserService: NSObject, IUserService {
  14. fileprivate var _user: User!
  15. fileprivate var _contacts: [Contact]!
  16.  
  17. override init(){
  18. self._user = User()
  19. self._contacts = [Contact]()
  20. }
  21.  
  22. func logIn(_ ilogin: String, ipassword: String, remember: Bool, completion: @escaping ((_ result :[String : AnyObject])->Void)) -> Void
  23. {
  24. let url = URL(string: "http://libs.samtech.cl/movil/SesionUsuario.asp")
  25. let parameters: [String : AnyObject] = ["ilogin" : ilogin as AnyObject, "ipassword" : ipassword as AnyObject, "app" : "Isamtech" as AnyObject]
  26.  
  27. var msg = "Credenciales no válidas, intente de nuevo."
  28. var data : [String : AnyObject] = ["user" : "" as AnyObject, "vehicle" : "" as AnyObject]
  29. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "message" : msg as AnyObject, "data": data as AnyObject]
  30.  
  31.  
  32. let url2 = URL(string:"http://libs.samtech.cl/movil/InsertaDeviceToken.asp")
  33. let parameters2: [String : AnyObject] = ["ilogin" : ilogin as AnyObject, "ipassword" : ipassword as AnyObject, "app" : "Isamtech" as AnyObject, "deviceToken" : LibraryAPI.sharedInstance.getDeviceToken() as AnyObject]
  34.  
  35. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON
  36. {
  37. response in
  38. if response.result.isSuccess {
  39. let json = JSON(response.result.value!)
  40. print(json)
  41. Alamofire.request(url2!, method: .post, parameters: parameters2)
  42. if let users = json["users"].arrayObject {
  43. if users.count > 0 {
  44. for user_ in users{
  45. let user = user_ as AnyObject
  46. if user.value(forKey: "mensaje") as! String == "1" {
  47. self._user.ilogin = ilogin
  48. self._user.ipassword = ipassword
  49. self._user.type = user.value(forKey: "tipo_usuario")
  50. as! String == "1" ? 1 : 0
  51. self._user.state = user.value(forKey: "estado")
  52. as! String == "1" ? true : false
  53. self._user.hasSpeed = user.value(forKey: "contro_vel")
  54. as! String == "1" ? true : false
  55. self._user.contaUso = user.value(forKey: "conta_uso")
  56. as! String == "1" ? 1 : 0
  57. self._user.isDemo = user.value(forKey: "demo") as!
  58. String == "1" ? true : false
  59. self._user.hasNotifications = user.value(forKey: "notifi")
  60. as! String == "1" ? true : false
  61. self._user.total = Int(user.value(forKey: "total") as! String)
  62. self._user.isMasivo = user.value(forKey: "usuario") as! String
  63. == "MASIVO" ? true : false
  64. self._user.remember = remember
  65.  
  66. data.updateValue(self._user, forKey: "user")
  67. if (self._user.total == 1){
  68. let vehicle: Vehicle = Vehicle(idGPS: user.value(forKey: "gps") as! String, plate: user.value(forKey: "patente") as! String, state: user.value(forKey: "estado") as! String == "1" ? true : false, name: "Vehicle", speed: user.value(forKey: "contro_vel") as! String, hasIgnition: false)
  69. vehicle.cu_state = user.value(forKey: "conta_uso") as! String == "1" ? true: false
  70.  
  71.  
  72. data.updateValue(vehicle, forKey: "vehicle")
  73. LibraryAPI.sharedInstance.setVehicle(vehicle)
  74.  
  75.  
  76. }
  77.  
  78.  
  79. resultAPI.updateValue(true as AnyObject, forKey: "status")
  80. resultAPI.updateValue(data as AnyObject, forKey: "data")
  81. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  82. }
  83. }
  84.  
  85. }
  86. }
  87. }
  88. else{
  89. msg = "Error en la conexión. Intente de nuevo"
  90. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  91. }
  92. completion(resultAPI)
  93. }
  94. }
  95.  
  96.  
  97.  
  98. func requestPassword(_ ilogin: String){
  99. let url = URL(string: "http://libs.samtech.cl/movil/RecuperaContrasena.asp?")
  100. let parameters: [String : AnyObject] = ["ilogin" : ilogin as AnyObject]
  101.  
  102. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{response in
  103. if response.result.isSuccess {
  104. if let jsonResponse = JSON(response.result.value!)["contrasena"]
  105. .arrayObject{
  106. for response_ in jsonResponse{
  107. let response = response_ as AnyObject
  108. let message = response.value(forKey: "mensaje") as! String
  109. NotificationCenter.default.post(
  110. name: Foundation.Notification.Name(rawValue: "requestPasswordResponse"),
  111. object: self, userInfo: ["mensaje" : message])
  112. }
  113. }
  114. } else {
  115. print(response.result.error)
  116. }
  117. }
  118. }
  119.  
  120. func setCurrentUser(_ user: User){
  121. self._user = user
  122. }
  123.  
  124. func getCurrentUser() -> User{
  125. return self._user
  126. }
  127.  
  128. func sos(_ user: User, lat: String, lon: String){
  129.  
  130. let url = URL(string: "http://libs.samtech.cl/movil/AlarmaSOS.asp?")
  131. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject, "ipassword": user.ipassword as AnyObject,
  132. "latitud": lat as AnyObject, "longitud": lon as AnyObject]
  133. var message: String = String()
  134.  
  135. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{response in
  136. if response.result.isSuccess{
  137. if let jsonResponse = JSON(response.result.value!)["SOS"].arrayObject {
  138. for response_ in jsonResponse {
  139. let response = response_ as AnyObject
  140. message = response.value(forKey: "mensaje") as! String
  141. }
  142.  
  143. NotificationCenter.default.post(
  144. name: Foundation.Notification.Name(rawValue: "getSosResponse"), object: self, userInfo:
  145. ["mensaje": message])
  146. }
  147. } else {
  148.  
  149. }
  150. }
  151. }
  152.  
  153. func getContacts(){
  154. let url = URL(string: "http://libs.samtech.cl/movil/contacto.asp?")
  155. let parameters: [String : AnyObject] = ["ilogin": LibraryAPI.sharedInstance.getCurrentUser().ilogin as AnyObject, "ipassword": LibraryAPI.sharedInstance.getCurrentUser().ipassword as AnyObject,
  156. "Sw": "1" as AnyObject, "id_cont": "" as AnyObject, "nombre": "" as AnyObject, "telefono": "" as AnyObject, "mail": "" as AnyObject]
  157.  
  158. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{response in
  159.  
  160. if response.result.isSuccess{
  161. if let jsonResponse = JSON(response.result.value!)["lista"].arrayObject {
  162. for contact_ in jsonResponse {
  163. let contact = contact_ as AnyObject
  164. let contactDTO: Contact = Contact(
  165. id: contact.value(forKey: "ID_cont") as! String,
  166. name: contact.value(forKey: "Nombre") as! String,
  167. phone: contact.value(forKey: "Telefono") as! String,
  168. email: contact.value(forKey: "eMail") as! String)
  169.  
  170. self._contacts.append(contactDTO)
  171. }
  172.  
  173. NotificationCenter.default.post(
  174. name: Foundation.Notification.Name(rawValue: "getContactsResponse"), object: self, userInfo:
  175. ["contacts": self._contacts])
  176. }
  177. } else {
  178.  
  179. }
  180. }
  181. }
  182.  
  183. func getContacts(_ completion: @escaping ((_ result :[String : AnyObject])->Void)) -> Void
  184. {
  185.  
  186. let url = URL(string: "http://libs.samtech.cl/movil/contacto.asp?")
  187. let parameters: [String : AnyObject] = ["ilogin": LibraryAPI.sharedInstance.getCurrentUser().ilogin as AnyObject, "ipassword": LibraryAPI.sharedInstance.getCurrentUser().ipassword as AnyObject,
  188. "Sw": "1" as AnyObject, "id_cont": "" as AnyObject, "nombre": "" as AnyObject, "telefono": "" as AnyObject, "mail": "" as AnyObject]
  189.  
  190. var msg = "error request"
  191. var contacts_dto : [Contact] = [Contact]()
  192.  
  193. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "data" : contacts_dto as AnyObject, "message" : msg as AnyObject]
  194.  
  195. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{
  196. response in
  197.  
  198. if response.result.isSuccess{
  199. if let jsonResponse = JSON(response.result.value!)["lista"].arrayObject {
  200. for contact_ in jsonResponse {
  201. let contact = contact_ as AnyObject
  202. let contactDTO: Contact = Contact(
  203. id: contact.value(forKey: "ID_cont") as! String,
  204. name: contact.value(forKey: "Nombre") as! String,
  205. phone: contact.value(forKey: "Telefono") as! String,
  206. email: contact.value(forKey: "eMail") as! String)
  207.  
  208. contacts_dto.append(contactDTO)
  209. }
  210.  
  211. if (contacts_dto.isEmpty) {
  212. let fake_user = Contact(
  213. id: "-1",
  214. name: "No tiene contactos disponibles",
  215. phone: "--",
  216. email: "--")
  217. contacts_dto.append(fake_user)
  218. msg = "empty response"
  219. }else {
  220. msg = "successful response"
  221. }
  222. resultAPI.updateValue(true as AnyObject, forKey: "status")
  223. resultAPI.updateValue(contacts_dto as AnyObject, forKey: "data")
  224. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  225. }
  226. }else{
  227. msg = "Error en la consulta, verifique su conexión."
  228. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  229. }
  230. completion(resultAPI)
  231. }
  232.  
  233. }
  234.  
  235. func getUserList(_ completion: @escaping ((_ result :[String : AnyObject])->Void)) -> Void
  236. {
  237. let url: String = "http://libs.samtech.cl/movil/ConsultaUsuario.asp"
  238. let user: User = LibraryAPI.sharedInstance.getCurrentUser()
  239. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject,"ipassword": user.ipassword as AnyObject]
  240.  
  241. var msg = "error request"
  242. var usuarios_dto : [User] = [User]()
  243.  
  244. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "data" : usuarios_dto as AnyObject, "message" : msg as AnyObject]
  245.  
  246. Alamofire.request(url, method: .post, parameters: parameters).responseJSON{
  247. response in
  248. if response.result.isSuccess
  249. {
  250. if let jsonResponse = JSON(response.result.value!)["usuarios"].arrayObject {
  251.  
  252. for usuario_ in jsonResponse {
  253. let usuario = usuario_ as AnyObject
  254. let userDTO : User = User(ilogin: usuario["Usuario"] as! String,
  255. ipassword: usuario["Clave"] as! String,
  256. tipo: 2,
  257. email: usuario["Mail"] as! String,
  258. nombre: usuario["Nombre"] as! String,
  259. fono: usuario["Fono"] as! String
  260. )
  261. usuarios_dto.append(userDTO)
  262. }
  263. if (usuarios_dto.isEmpty) {
  264. let fake_user = User(ilogin: "No tiene usuarios disponibles", ipassword: "", tipo: 0, email: "", nombre: "No tiene usuarios disponibles", fono: "")
  265. usuarios_dto.append(fake_user)
  266. msg = "empty response"
  267. }else {
  268. msg = "successful response"
  269. }
  270. resultAPI.updateValue(true as AnyObject, forKey: "status")
  271. resultAPI.updateValue(usuarios_dto as AnyObject, forKey: "data")
  272. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  273. }
  274.  
  275. }else{
  276. msg = "Error en la consulta, verifique su conexión."
  277. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  278. }
  279. completion(resultAPI)
  280. }
  281. }
  282.  
  283. func ActualizarNotificaciones(_ accion_id: String, estado_id: String, notificacion_id: String, completion: @escaping ((_ result :[String : AnyObject])->Void)) -> Void
  284. {
  285. let url: String = "http://libs.samtech.cl/movil/Notificaciones.asp"
  286. let user: User = LibraryAPI.sharedInstance.getCurrentUser()
  287. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject,"ipassword": user.ipassword as AnyObject, "accion": accion_id as AnyObject, "estado" : estado_id as AnyObject, "Id_notificacion" : notificacion_id as AnyObject]
  288.  
  289. var msg = "error request"
  290. var notification_dto : [Notification] = [Notification]()
  291.  
  292. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "data" : notification_dto as AnyObject, "message" : msg as AnyObject]
  293.  
  294. Alamofire.request(url, method: .post, parameters: parameters).responseJSON{
  295. response in
  296. if response.result.isSuccess
  297. {
  298. if let jsonResponse = JSON(response.result.value!)["notificaciones"].arrayObject {
  299.  
  300. if accion_id == "1" {
  301. for notificacion_ in jsonResponse {
  302. let notificacion = notificacion_ as AnyObject
  303.  
  304. let notificacionDTO :Notification = Notification(gps: notificacion["GPS"] as! String, descripcion: notificacion["Descripcion"] as! String, leyenda: notificacion["Leyenda"] as! String, estado: notificacion["Estado"] as! String, esu_id: notificacion["Esu_id"] as! String,patente: "", fechaIni :"",fechaTer: "")
  305. notification_dto.append(notificacionDTO)
  306. }
  307. }
  308. if (notification_dto.isEmpty) {
  309. let fake_notification = Notification(
  310. gps: "-1",
  311. descripcion: "No tiene notificaciones",
  312. leyenda: "",
  313. estado: "",
  314. esu_id: "",
  315. patente: "",
  316. fechaIni :"",
  317. fechaTer: ""
  318. )
  319. notification_dto.append(fake_notification)
  320. msg = "empty response"
  321. }else {
  322. msg = "successful response"
  323. }
  324.  
  325. resultAPI.updateValue(true as AnyObject, forKey: "status")
  326. resultAPI.updateValue(notification_dto as AnyObject, forKey: "data")
  327. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  328. }
  329.  
  330. }
  331. else{
  332. msg = "Error en la consulta, verifique su conexión."
  333. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  334. }
  335. completion(resultAPI)
  336. }
  337.  
  338. }
  339.  
  340. func getNamesPerPlates(_ gps_id: String, patente_id: String, nombre_id: String, accion_id: String, completion: @escaping ((_ result :[String : AnyObject])->Void)) -> Void
  341. {
  342. let url = String("http://libs.samtech.cl/movil/NombrePorPatente.asp")
  343. let user: User = LibraryAPI.sharedInstance.getCurrentUser()
  344. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject,"ipassword": user.ipassword as AnyObject, "accion": accion_id as AnyObject, "patente": patente_id as AnyObject, "gps": gps_id as AnyObject ]
  345.  
  346.  
  347. var msg = "error request"
  348. var vehicles_dto : [Vehicle] = [Vehicle]()
  349.  
  350. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "data" : vehicles_dto as AnyObject, "message" : msg as AnyObject]
  351.  
  352.  
  353. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{
  354. response in
  355. if response.result.isSuccess
  356. {
  357. if let jsonResponse = JSON(response.result.value!)["NomPatente"].arrayObject {
  358. for vehicle_ in jsonResponse {
  359. let vehicle = vehicle_ as AnyObject
  360. let vehicle_dto = Vehicle(
  361. idGPS: vehicle.value(forKey: "GPS") as! String,
  362. plate: vehicle.value(forKey: "Patente") as! String,
  363. name: vehicle.value(forKey: "Nombre") as! String
  364. )
  365.  
  366. vehicles_dto.append(vehicle_dto)
  367. }
  368. if (vehicles_dto.isEmpty) {
  369. let fake_vehicle = Vehicle(idGPS: "-1", plate: "--", name: "No tiene vehiculos disponibles")
  370. vehicles_dto.append(fake_vehicle)
  371. msg = "empty response"
  372. }else {
  373. msg = "successful response"
  374. }
  375.  
  376. resultAPI.updateValue(true as AnyObject, forKey: "status")
  377. resultAPI.updateValue(vehicles_dto as AnyObject, forKey: "data")
  378. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  379. }
  380.  
  381. }
  382. else{
  383. msg = "Error en la consulta, verifique su conexión."
  384. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  385. }
  386. completion(resultAPI)
  387. }
  388. }
  389.  
  390. func updateNamesPerPlates(_ gps_id: String, patente_id: String, nombre_id: String, completion: @escaping ((_ result :[String : AnyObject])->Void)) -> Void
  391. {
  392.  
  393. let url = String("http://libs.samtech.cl/movil/NombrePorPatente.asp")
  394. let user: User = LibraryAPI.sharedInstance.getCurrentUser()
  395. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject,"ipassword": user.ipassword as AnyObject, "accion": "2" as AnyObject, "patente": patente_id as AnyObject, "gps": gps_id as AnyObject, "Nombre": nombre_id as AnyObject]
  396.  
  397.  
  398. var msg = "error request"
  399. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "message" : msg as AnyObject]
  400.  
  401.  
  402. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{
  403. response in
  404. if response.result.isSuccess
  405. {
  406. if let jsonResponse = JSON(response.result.value!)["NomPatente"].arrayObject {
  407.  
  408. for response_ in jsonResponse {
  409. let r = response_ as AnyObject
  410. msg = r.value(forKey: "GPS") as! String
  411. if msg == "Patente Actualizada" {
  412. resultAPI.updateValue(true as AnyObject, forKey: "status")
  413. }
  414. }
  415. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  416. }
  417.  
  418. }
  419. else{
  420. msg = "Error en la consulta, verifique su conexión."
  421. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  422. }
  423. completion(resultAPI)
  424. }
  425.  
  426.  
  427. }
  428.  
  429. func updateContact(_ contenido_id: String, nombre_id: String, telefono_id: String, mail_id: String, accion_id: String, completion: @escaping ((_ result :[String : AnyObject])->Void)) -> Void
  430. {
  431. let url = URL(string: "http://libs.samtech.cl/movil/contacto.asp")
  432. let user: User = LibraryAPI.sharedInstance.getCurrentUser()
  433. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject, "ipassword": user.ipassword as AnyObject, "Sw": accion_id as AnyObject, "Id_cont": contenido_id as AnyObject, "Nombre": nombre_id as AnyObject, "Telefono": telefono_id as AnyObject, "Mail": mail_id as AnyObject]
  434.  
  435. var msg = "error request"
  436. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "message" : msg as AnyObject]
  437.  
  438. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{
  439. response in
  440. if response.result.isSuccess{
  441. if let jsonResponse = JSON(response.result.value!)["lista"].arrayObject {
  442. for contact_ in jsonResponse {
  443. let contact = contact_ as AnyObject
  444. msg = contact.value(forKey: "Nombre") as! String
  445.  
  446. if msg == "Usuario Registrado" || msg == "Contacto actualizado" || msg == "Contacto eliminado"
  447. {
  448. resultAPI.updateValue(true as AnyObject, forKey: "status")
  449. }
  450. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  451.  
  452. }
  453. }
  454. }else{
  455. msg = "Error en la consulta, verifique su conexión."
  456. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  457. }
  458. completion(resultAPI)
  459. }
  460. }
  461.  
  462. func assignVehiclesPerUser(_ user_id: String, gps_id: String, patente_id: String, estado_id: String, accion_id: String, completion : @escaping ((_ result: [String: AnyObject])-> Void)) -> Void
  463. {
  464.  
  465. let url = URL(string: "http://libs.samtech.cl/movil/AsignaVehiculosPorUsuario.asp")
  466. let user: User = LibraryAPI.sharedInstance.getCurrentUser()
  467. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject,"ipassword": user.ipassword as AnyObject, "id": gps_id as AnyObject, "usuario":user_id as AnyObject, "patente":patente_id as AnyObject, "estado":estado_id as AnyObject, "accion":accion_id as AnyObject]
  468.  
  469. var msg = "error request"
  470.  
  471. var vehicles_dto : [Vehicle] = []
  472. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "message" : msg as AnyObject, "data": vehicles_dto as AnyObject]
  473.  
  474. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{
  475. response in
  476. if response.result.isSuccess{
  477. if let responses = JSON(response.result.value!)["vehiculos"].arrayObject {
  478. for response_ in responses {
  479. let response = response_ as AnyObject
  480. let vehicle_dto = Vehicle(idGPS: response.value(forKey: "GPS") as! String, plate: response.value(forKey: "Patente") as! String, state: response.value(forKey: "Estado") as! String == "1" ? true : false, name: "", speed: "")
  481. vehicles_dto.append(vehicle_dto)
  482. }
  483. resultAPI.updateValue(vehicles_dto as AnyObject, forKey: "data")
  484. resultAPI.updateValue(true as AnyObject, forKey: "status")
  485.  
  486.  
  487. }
  488. }else{
  489. msg = "Error en la consulta, verifique su conexión."
  490. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  491. }
  492. completion(resultAPI)
  493. }
  494.  
  495. }
  496.  
  497. func insertUser(_ user_id: String, name: String, password: String, mail: String, phone: String, type: String, completion: @escaping (_ result: [String:AnyObject]) -> Void) -> Void
  498. {
  499.  
  500.  
  501. let url = URL(string: "http://libs.samtech.cl/movil/InsertaUsuario.asp")
  502. let user: User = LibraryAPI.sharedInstance.getCurrentUser()
  503. let parameters: [String : AnyObject] = ["ilogin": user.ilogin as AnyObject,"ipassword": user.ipassword as AnyObject, "usuario": user_id as AnyObject, "Nombre_usu": name as AnyObject, "Clave_usuario": password as AnyObject, "Mail_usuario": mail as AnyObject, "Tipo_ingreso": type as AnyObject, "fono": phone as AnyObject, "tipo_usu": "2" as AnyObject, "app": "Isamtech" as AnyObject]
  504.  
  505. var resultAPI : [String : AnyObject] = ["status" : false as AnyObject, "message" : "" as AnyObject, "success" : false as AnyObject]
  506.  
  507. Alamofire.request(url!, method: .post, parameters: parameters).responseJSON{
  508. response in
  509. if response.result.isSuccess{
  510. if let responses = JSON(response.result.value!)["usuario"].arrayObject {
  511. for response_ in responses {
  512. let response = response_ as AnyObject
  513. let mensaje = response.value(forKey: "mensaje") as! String
  514. if(mensaje == "Usuario ingresados" || mensaje == "Usuario actualizado")
  515. {
  516. resultAPI.updateValue(true as AnyObject, forKey: "success")
  517. }
  518. resultAPI.updateValue(mensaje as AnyObject, forKey: "message")
  519. }
  520. resultAPI.updateValue(true as AnyObject, forKey: "status")
  521.  
  522.  
  523. }
  524. }else{
  525. let msg = "Error en la consulta, verifique su conexión."
  526. resultAPI.updateValue(msg as AnyObject, forKey: "message")
  527. }
  528. completion(resultAPI)
  529. }
  530. }
  531. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement