DeviceManagerViewModel.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // DeviceManagerViewModel.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/5/7.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import CocoaLumberjack
  9. import Promises
  10. import O2OA_Auth_SDK
  11. class DeviceManagerViewModel: NSObject {
  12. /**
  13. * 获取设备列表
  14. */
  15. func getDeviceList() -> Promise<[O2BindDeviceModel]> {
  16. return Promise<[O2BindDeviceModel]>{ fulfill, reject in
  17. let mobile = O2AuthSDK.shared.bindDevice()?.mobile
  18. let token = O2AuthSDK.shared.bindDevice()?.name
  19. let unit = O2AuthSDK.shared.bindUnit()?.id
  20. if mobile == nil || unit == nil || token == nil {
  21. reject(OOAppError.common(type: "parameterError", message: "获取不到绑定的信息", statusCode: 1024))
  22. }else {
  23. O2AuthSDK.shared.bindDeviceList(unitId: unit!, mobile: mobile!, token: token!, callback: { (list, error) in
  24. if error != nil {
  25. reject(OOAppError.apiResponseError(error!))
  26. }else {
  27. fulfill(list)
  28. }
  29. })
  30. }
  31. }
  32. }
  33. /**
  34. * 解绑设备
  35. */
  36. func unbindDevice(token: String) -> Promise<Bool> {
  37. return Promise<Bool> {fulfill, reject in
  38. O2AuthSDK.shared.unBindFromCollect(deviceId: token) { (result, error) in
  39. if error != nil {
  40. reject(OOAppError.apiResponseError(error!))
  41. }else {
  42. fulfill(true)
  43. }
  44. }
  45. }
  46. }
  47. }