O2JPushManager.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // O2JPushManager.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/11/11.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Moya
  10. import Promises
  11. import CocoaLumberjack
  12. class O2JPushManager {
  13. static let shared: O2JPushManager = {
  14. return O2JPushManager()
  15. }()
  16. private init() {
  17. }
  18. private let o2JPushAPI = {
  19. return OOMoyaProvider<JPushAPI>()
  20. }()
  21. //直连版本 连接o2oa服务器绑定设备号到个人属性中
  22. func o2JPushBind() {
  23. DDLogDebug("绑定设备号")
  24. if let _ = O2AuthSDK.shared.o2APIServer(context: .x_jpush_assemble_control) {
  25. let deviceName = O2AuthSDK.shared.getDeviceToken()
  26. let device = JPushDevice()
  27. device.deviceName = deviceName
  28. device.deviceType = "ios"
  29. self.o2JPushAPI.request(.bindDevice(device)) { (result) in
  30. let response = OOResult<BaseModelClass<OOCommonValueBoolModel>>(result)
  31. if response.isResultSuccess() {
  32. let value = response.model?.data
  33. DDLogInfo("绑定设备到个人属性,结果:\(value?.value ?? false)")
  34. }else {
  35. DDLogError(response.error?.localizedDescription ?? "绑定设备到个人属性失败!")
  36. }
  37. }
  38. }else {
  39. DDLogError("绑定,没有获取到极光推送消息模块,服务器版本不支持!!!!!")
  40. }
  41. }
  42. func O2JPushUnBind() {
  43. DDLogDebug("解除绑定设备号")
  44. if let _ = O2AuthSDK.shared.o2APIServer(context: .x_jpush_assemble_control) {
  45. let deviceName = O2AuthSDK.shared.getDeviceToken()
  46. self.o2JPushAPI.request(.unBindDevice(deviceName)) { (result) in
  47. let response = OOResult<BaseModelClass<OOCommonValueBoolModel>>(result)
  48. if response.isResultSuccess() {
  49. let value = response.model?.data
  50. DDLogInfo("解绑设备号 ,结果:\(value?.value ?? false)")
  51. }else {
  52. DDLogError(response.error?.localizedDescription ?? "解绑设备号 失败!")
  53. }
  54. }
  55. }else {
  56. DDLogError("解绑,没有获取到极光推送消息模块,服务器版本不支持!!!!!")
  57. }
  58. }
  59. }