CommonUMengShare.swift 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // CommonUMengShare.swift
  3. // CommonFrame
  4. //
  5. // Created by Virgil on 2017/1/10.
  6. // Copyright © 2017年 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class CommonUMengShare: NSObject {
  10. class func showSharedMenuCus(viewController: UIViewController, title: String, desc: String, icon: UIImage, url: String, img: UIImage) {
  11. UMSocialUIManager.addCustomPlatformWithoutFilted(UMSocialPlatformType(rawValue: 1002)!, withPlatformIcon: UIImage(named: "code_news"), withPlatformName: "二维码海报")
  12. CommonOC.setUMCus()
  13. UMSocialUIManager.showShareMenuViewInWindow { (type, _) in
  14. if type.rawValue == 1002 {
  15. let messageObject = UMSocialMessageObject()
  16. //内容体 (分享图文:UMShareImageObject 音乐:UMShareMusicObject 视频:UMShareVideoObject
  17. let messagess = UMShareImageObject()
  18. messagess.shareImage = img
  19. messageObject.shareObject = messagess
  20. UMSocialManager.default().share(to: .wechatTimeLine, messageObject: messageObject, currentViewController: viewController, completion: { (_, _) in
  21. })
  22. } else {
  23. let messageObject = UMSocialMessageObject()
  24. //内容体 (分享图文:UMShareImageObject 音乐:UMShareMusicObject 视频:UMShareVideoObject
  25. let messagess = UMShareWebpageObject()
  26. messagess.descr = desc
  27. messagess.title = title
  28. messagess.webpageUrl = url
  29. messagess.thumbImage = icon
  30. messageObject.shareObject = messagess
  31. UMSocialManager.default().share(to: type, messageObject: messageObject, currentViewController: viewController, completion: { (_, error) in
  32. print("=======error==\(String(describing: error))=")
  33. })
  34. }
  35. }
  36. }
  37. class func showSharedMenu(viewController: UIViewController, title: String, desc: String, icon: UIImage, url: String) {
  38. UMSocialUIManager.removeCustomPlatformWithoutFilted(UMSocialPlatformType(rawValue: 1002)!)
  39. CommonOC.setUM()
  40. // UMSocialUIManager.setPreDefinePlatforms([UMSocialPlatformType.wechatSession,UMSocialPlatformType.wechatTimeLine])
  41. UMSocialUIManager.addCustomPlatformWithoutFilted(.userDefine_Begin, withPlatformIcon: UIImage(named: "code_news"), withPlatformName: "二维码海报")
  42. UMSocialUIManager.showShareMenuViewInWindow { (type, _) in
  43. let messageObject = UMSocialMessageObject()
  44. //内容体 (分享图文:UMShareImageObject 音乐:UMShareMusicObject 视频:UMShareVideoObject
  45. let messagess = UMShareWebpageObject()
  46. messagess.descr = desc
  47. messagess.title = title
  48. messagess.webpageUrl = url
  49. messagess.thumbImage = icon
  50. messageObject.shareObject = messagess
  51. UMSocialManager.default().share(to: type, messageObject: messageObject, currentViewController: viewController, completion: { (_, error) in
  52. print("=======error==\(String(describing: error))=")
  53. })
  54. }
  55. }
  56. class func showSharedMenu(viewController: UIViewController, title: String, desc: String, icon: UIImage, url: String, reBack:@escaping RebackFunction) {
  57. UMSocialUIManager.removeCustomPlatformWithoutFilted(UMSocialPlatformType(rawValue: 1002)!)
  58. CommonOC.setUM()
  59. // UMSocialUIManager.setPreDefinePlatforms([UMSocialPlatformType.wechatSession,UMSocialPlatformType.wechatTimeLine])
  60. UMSocialUIManager.showShareMenuViewInWindow { (type, _) in
  61. let messageObject = UMSocialMessageObject()
  62. //内容体 (分享图文:UMShareImageObject 音乐:UMShareMusicObject 视频:UMShareVideoObject
  63. let messagess = UMShareWebpageObject()
  64. messagess.descr = desc
  65. messagess.title = title
  66. messagess.webpageUrl = url
  67. messagess.thumbImage = icon
  68. messageObject.shareObject = messagess
  69. UMSocialManager.default().share(to: type, messageObject: messageObject, currentViewController: viewController, completion: { (_, error) in
  70. if error == nil {
  71. reBack(1, "")
  72. } else {
  73. reBack(0, "")
  74. }
  75. })
  76. }
  77. }
  78. class func showSharedMenuWX(viewController: UIViewController, title: String, desc: String, icon: UIImage, url: String, reBack:@escaping RebackFunction) {
  79. UMSocialUIManager.removeCustomPlatformWithoutFilted(UMSocialPlatformType(rawValue: 1002)!)
  80. CommonOC.setUMWX()
  81. // UMSocialUIManager.setPreDefinePlatforms([UMSocialPlatformType.wechatSession,UMSocialPlatformType.wechatTimeLine])
  82. UMSocialUIManager.showShareMenuViewInWindow { (type, _) in
  83. let messageObject = UMSocialMessageObject()
  84. //内容体 (分享图文:UMShareImageObject 音乐:UMShareMusicObject 视频:UMShareVideoObject
  85. let messagess = UMShareWebpageObject()
  86. messagess.descr = desc
  87. messagess.title = title
  88. messagess.webpageUrl = url
  89. messagess.thumbImage = icon
  90. messageObject.shareObject = messagess
  91. UMSocialManager.default().share(to: type, messageObject: messageObject, currentViewController: viewController, completion: { (_, error) in
  92. if error == nil {
  93. reBack(1, "")
  94. } else {
  95. reBack(0, "")
  96. }
  97. })
  98. }
  99. }
  100. class func showSharedMenu(viewController: UIViewController, img: UIImage, reBack:@escaping RebackFunction) {
  101. UMSocialUIManager.removeCustomPlatformWithoutFilted(UMSocialPlatformType(rawValue: 1002)!)
  102. CommonOC.setUM()
  103. // UMSocialUIManager.setPreDefinePlatforms([UMSocialPlatformType.wechatSession,UMSocialPlatformType.wechatTimeLine])
  104. UMSocialUIManager.showShareMenuViewInWindow { (type, _) in
  105. let messageObject = UMSocialMessageObject()
  106. //内容体 (分享图文:UMShareImageObject 音乐:UMShareMusicObject 视频:UMShareVideoObject
  107. let messagess = UMShareImageObject()
  108. messagess.shareImage = img
  109. messageObject.shareObject = messagess
  110. UMSocialManager.default().share(to: type, messageObject: messageObject, currentViewController: viewController, completion: { (_, error) in
  111. if error == nil {
  112. reBack(1, "")
  113. } else {
  114. reBack(0, "")
  115. }
  116. })
  117. }
  118. }
  119. //第三方登陆
  120. class func thirdLogin(viewController: UIViewController, platformType: UMSocialPlatformType) {
  121. UMSocialManager.default().getUserInfo(with: platformType, currentViewController: viewController) { (result, _) in
  122. let resp = result as! UMSocialUserInfoResponse
  123. print(" uid: \(resp.uid ?? "")")
  124. print(" openid: \(resp.openid ?? "")")
  125. print(" accessToken: \(resp.accessToken ?? "")")
  126. print(" refreshToken: \(resp.refreshToken ?? "")")
  127. print(" expiration: \(String(describing: resp.expiration))")
  128. // 用户数据
  129. print(" name: \(resp.name ?? "")")
  130. print(" iconurl: \(resp.iconurl ?? "")")
  131. print(" gender: \(resp.gender ?? "")")
  132. // 第三方平台SDK原始数据
  133. print(" originalResponse: \(String(describing: resp.originalResponse))")
  134. }
  135. }
  136. }