经过(一)的讲解,大家应该可以按照友盟提供的测试账号可以集成友盟分享了,友盟目前集合了18个APP共27种分享,可以授权的有10个App:微信、QQ、新浪微博、腾讯微博、人人网、豆瓣、Facebook、Twitter、Linkedin领英、Kakao。
(二)主要在(一)基础上加了音乐、视频分享,替换了友盟的部分测试账号为自己申请的appKey和appSecret,注意替换时不仅要替换AppDelegate.Swift中的application didFinishLaunchingWithOptions的代码,还要同时替换Info中的URL Types,两者是配套使用的!

作者首先申请了友盟的Appkey 5832b93b99f0c74ef10019c8,在didFinishLaunchingWithOptions的代码中替换,同时对微博微信 QQ这三个主流的Open平台进行了申请

微博

1577306477

b1f0cd8cd2140c407a8c20c319155df8

QQ

1105839186

CKFSBH6Fw21RN5pu

微信

wxd795d58c78ac222b

779c58188ca57046f76353ea1e84412c

代码如下

[objc] view plaincopy
  1. //
  2. //  AppDelegate.swift
  3. //  umengtest
  4. //
  5. //  Created by targetcloud on 2016/11/21.
  6. //  Copyright © 2016年 targetcloud. All rights reserved.
  7. //
  8. import UIKit
  9. @UIApplicationMain
  10. class AppDelegate: UIResponder, UIApplicationDelegate {
  11. var window: UIWindow?
  12. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  13. UMSocialManager.default().openLog(true)
  14. UMSocialManager.default().umSocialAppkey = "57b432afe0f55a9832001a0a"
  15. //        UMSocialManager.default().umSocialAppkey = "5832b93b99f0c74ef10019c8"
  16. print("UMeng social version:\(UMSocialGlobal.umSocialSDKVersion())" );
  17. UMSocialManager.default().setPlaform(UMSocialPlatformType.wechatSession, appKey: "wxdc1e388c3822c80b", appSecret: "3baf1193c85774b3fd9d18447d76cab0", redirectURL: "http://mobile.umeng.com/social")
  18. //        UMSocialManager.default().setPlaform(UMSocialPlatformType.wechatSession, appKey: "wxd795d58c78ac222b", appSecret: "779c58188ca57046f76353ea1e84412c", redirectURL: "http://mobile.umeng.com/social")
  19. UMSocialManager.default().setPlaform(UMSocialPlatformType.QQ, appKey: "100424468", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
  20. //        UMSocialManager.default().setPlaform(UMSocialPlatformType.QQ, appKey: "1105839186", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
  21. UMSocialManager.default().setPlaform(UMSocialPlatformType.alipaySession, appKey: "2015111700822536", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
  22. UMSocialManager.default().setPlaform(UMSocialPlatformType.yixinSession, appKey: "yx35664bdff4db42c2b7be1e29390c1a06", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
  23. UMSocialManager.default().setPlaform(UMSocialPlatformType.laiWangSession, appKey: "8112117817424282305", appSecret: "9996ed5039e641658de7b83345fee6c9", redirectURL: "http://mobile.umeng.com/social")
  24. UMSocialManager.default().setPlaform(UMSocialPlatformType.sina, appKey: "3921700954", appSecret: "04b48b094faeb16683c32669824ebdad", redirectURL: "http://sns.whalecloud.com/sina2/callback")
  25. //        UMSocialManager.default().setPlaform(UMSocialPlatformType.sina, appKey: "1577306477", appSecret: "b1f0cd8cd2140c407a8c20c319155df8", redirectURL: "http://sns.whalecloud.com/sina2/callback")
  26. UMSocialManager.default().setPlaform(UMSocialPlatformType.linkedin, appKey: "81t5eiem37d2sc", appSecret: "7dgUXPLH8kA8WHMV", redirectURL: "https://api.linkedin.com/v1/people")
  27. UMSocialManager.default().setPlaform(UMSocialPlatformType.twitter, appKey: "fB5tvRpna1CKK97xZUslbxiet", appSecret: "YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K", redirectURL: nil)
  28. UMSocialManager.default().setPlaform(UMSocialPlatformType.facebook, appKey: "506027402887373", appSecret: nil, redirectURL: "http://www.umeng.com/social")
  29. UMSocialManager.default().setPlaform(UMSocialPlatformType.pinterest, appKey: "4864546872699668063", appSecret: nil, redirectURL: nil)
  30. //        UMSocialManager.default().removePlatformProvider(withPlatformTypes: [UMSocialPlatformType.wechatFavorite,UMSocialPlatformType.yixinTimeLine,UMSocialPlatformType.laiWangTimeLine,UMSocialPlatformType.qzone])
  31. return true
  32. }
  33. func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  34. let result = UMSocialManager.default().handleOpen(url)
  35. if !result{
  36. }
  37. return result
  38. }
  39. func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
  40. let result = UMSocialManager.default().handleOpen(url)
  41. if !result{
  42. }
  43. return result
  44. }
  45. }
[objc] view plaincopy
  1. //
  2. //  ViewController.swift
  3. //  umengtest
  4. //
  5. //  Created by targetcloud on 2016/11/21.
  6. //  Copyright © 2016年 targetcloud. All rights reserved.
  7. //
  8. import UIKit
  9. class ViewController: UIViewController {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. let shareButton:UIButton = UIButton(frame: CGRect(x: 50, y: 50, width: 200, height: 50))
  13. //        shareButton.center = CGPoint(x: self.view.frame.size.width / 2, y: self.view.frame.size.height / 2)
  14. shareButton.setTitle("Swift图文分享", for: UIControlState())
  15. shareButton.addTarget(self, action: #selector(shareAction_pic), for: UIControlEvents.touchUpInside)
  16. shareButton.setTitleColor(UIColor.blue, for: UIControlState())
  17. shareButton.backgroundColor = UIColor.clear
  18. let sharewww : UIButton = UIButton(frame: CGRect(x: 50, y: 100, width: 200, height: 50))
  19. sharewww.setTitle("Swift网页分享", for: UIControlState())
  20. sharewww.addTarget(self, action: #selector(shareAction_www), for: UIControlEvents.touchUpInside)
  21. sharewww.setTitleColor(UIColor.blue, for: UIControlState())
  22. sharewww.backgroundColor = UIColor.clear
  23. let sharetxt : UIButton = UIButton(frame: CGRect(x: 50, y: 150, width: 200, height: 50))
  24. sharetxt.setTitle("Swift文字分享", for: UIControlState())
  25. sharetxt.addTarget(self, action: #selector(shareAction_txt), for: UIControlEvents.touchUpInside)
  26. sharetxt.setTitleColor(UIColor.blue, for: UIControlState())
  27. sharetxt.backgroundColor = UIColor.clear
  28. let shareMusic : UIButton = UIButton(frame: CGRect(x: 50, y: 200, width: 200, height: 50))
  29. shareMusic.setTitle("Swift音乐分享", for: UIControlState())
  30. shareMusic.addTarget(self, action: #selector(shareAction_music), for: UIControlEvents.touchUpInside)
  31. shareMusic.setTitleColor(UIColor.blue, for: UIControlState())
  32. shareMusic.backgroundColor = UIColor.clear
  33. let shareVideo : UIButton = UIButton(frame: CGRect(x: 50, y: 250, width: 200, height: 50))
  34. shareVideo.setTitle("Swift视频分享", for: UIControlState())
  35. shareVideo.addTarget(self, action: #selector(shareAction_video), for: UIControlEvents.touchUpInside)
  36. shareVideo.setTitleColor(UIColor.blue, for: UIControlState())
  37. shareVideo.backgroundColor = UIColor.clear
  38. self.view.addSubview(shareButton)
  39. self.view.addSubview(sharewww)
  40. self.view.addSubview(sharetxt)
  41. self.view.addSubview(shareMusic)
  42. self.view.addSubview(shareVideo)
  43. }
  44. func shareAction_pic (){
  45. UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shreMenuView, platformType) in
  46. let messageObject:UMSocialMessageObject = UMSocialMessageObject.init()
  47. messageObject.text = "友盟分享测试(图片),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
  48. let shareObject:UMShareImageObject = UMShareImageObject.init()
  49. shareObject.title = "图片分享"
  50. shareObject.descr = "这里是图片分享测试,作者:targetcloud"
  51. shareObject.thumbImage = UIImage.init(named: "icon")
  52. shareObject.shareImage = "http://dev.umeng.com/images/tab2_1.png"
  53. messageObject.shareObject = shareObject;
  54. UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (shareResponse, error) in
  55. if error != nil {
  56. print("Share Fail with error :%@", error)
  57. }else{
  58. self?.getUserInfoForPlatform(platformType: platformType)
  59. print("Share succeed")
  60. }
  61. })
  62. }
  63. }
  64. func shareAction_www (){
  65. UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shreMenuView, platformType) in
  66. let messageObject:UMSocialMessageObject = UMSocialMessageObject.init()
  67. messageObject.text = "友盟分享测试(网页),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
  68. let shareObject:UMShareWebpageObject = UMShareWebpageObject.init()
  69. shareObject.title = "网页分享"
  70. shareObject.descr = "这里是网页分享测试,作者:targetcloud"
  71. shareObject.thumbImage = UIImage.init(named: "icon")
  72. shareObject.webpageUrl = "http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html"
  73. messageObject.shareObject = shareObject;
  74. UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (shareResponse, error) in
  75. if error != nil {
  76. print("Share Fail with error :%@", error)
  77. }else{
  78. self?.getUserInfoForPlatform(platformType: platformType)
  79. print("Share succeed")
  80. }
  81. })
  82. }
  83. }
  84. func shareAction_txt (){
  85. UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in
  86. let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()
  87. messageObject.text = "友盟分享测试(文本),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
  88. UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (data:Any?, error:Error?) in
  89. if error != nil {
  90. print("************Share fail with error *********",error)
  91. }else{
  92. UMSocialManager.default().getUserInfo(with: platformType, currentViewController: self, completion: { (result:Any?, error:Error?) in
  93. if let userinfo  = result as? UMSocialUserInfoResponse{
  94. let message = " name: \(userinfo.name)\n icon: \(userinfo.iconurl)\n gender: \(userinfo.gender)\n"
  95. print(message)
  96. }
  97. })
  98. if let resp:UMSocialShareResponse = data as? UMSocialShareResponse  {
  99. print("response message is ",resp.message ?? "")
  100. print("response originalResponse data is ",resp.originalResponse ?? "")
  101. }
  102. print("response data is ",data)
  103. }
  104. self?.alertWithError(error: error)
  105. })
  106. }
  107. }
  108. func shareAction_music (){
  109. UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in
  110. let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()
  111. messageObject.text = "友盟分享测试(音乐),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
  112. let shareObject:UMShareMusicObject = UMShareMusicObject.init()
  113. shareObject.title = "音乐分享"
  114. shareObject.descr = "这里是音乐分享测试,作者:targetcloud"
  115. shareObject.thumbImage = UIImage.init(named: "icon")
  116. shareObject.musicUrl = "http://c.y.qq.com/v8/playsong.html?songid=108782194&source=yqq#wechat_redirect"
  117. messageObject.shareObject = shareObject;
  118. UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (data:Any?, error:Error?) in
  119. if error != nil {
  120. print("************Share fail with error *********",error)
  121. }else{
  122. if let resp:UMSocialShareResponse = data as? UMSocialShareResponse  {
  123. print("response message is ",resp.message ?? "")
  124. print("response originalResponse data is ",resp.originalResponse ?? "")
  125. }
  126. print("response data is ",data)
  127. }
  128. self?.alertWithError(error: error)
  129. })
  130. }
  131. }
  132. func shareAction_video (){
  133. UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in
  134. let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()
  135. messageObject.text = "友盟分享测试(视频),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
  136. let shareObject:UMShareVideoObject = UMShareVideoObject.init()
  137. shareObject.title = "视频分享"
  138. shareObject.descr = "这里是视频分享测试,作者:targetcloud"
  139. shareObject.thumbImage = UIImage.init(named: "icon")
  140. shareObject.videoUrl = "http://v.youku.com/v_show/id_XMTgyMjI1MjQxNg==.html?f=18252872#paction"
  141. messageObject.shareObject = shareObject;
  142. UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (data:Any?, error:Error?) in
  143. if error != nil {
  144. print("************Share fail with error *********",error)
  145. }else{
  146. if let resp:UMSocialShareResponse = data as? UMSocialShareResponse  {
  147. print("response message is ",resp.message ?? "")
  148. print("response originalResponse data is ",resp.originalResponse ?? "")
  149. }
  150. print("response data is ",data)
  151. }
  152. self?.alertWithError(error: error)
  153. })
  154. }
  155. }
  156. func alertWithError(error:Error?){
  157. var result = ""
  158. if (error == nil) {
  159. result = "恭喜你,分享成功!邀请好友一起玩吧!"
  160. }else{
  161. if(error != nil){
  162. result = "分享失败,此功能正在努力开通中..."
  163. }else{
  164. result = "额,分享失败了!"
  165. }
  166. }
  167. let alert = UIAlertView.init(title: "越分享,越快乐!", message: result, delegate: nil, cancelButtonTitle: NSLocalizedString("确定", comment: "确定"))
  168. alert.show()
  169. }
  170. func getUserInfoForPlatform(platformType:UMSocialPlatformType){
  171. UMSocialManager.default().getUserInfo(with: platformType, currentViewController: self, completion: { (result:Any?, error:Error?) in
  172. if let userinfo  = result as? UMSocialUserInfoResponse {
  173. let message = " name: \(userinfo.name)\n icon: \(userinfo.iconurl)\n gender: \(userinfo.gender)\n"
  174. print(message)
  175. let alert = UIAlertView.init(title: "UserInfo", message: message, delegate: nil, cancelButtonTitle: NSLocalizedString("确定", comment: "确定"))
  176. alert.show()
  177. }
  178. })
  179. }
  180. }

集成步骤不再重复,请按照(一)是肯定可以成功集成的

运行效果如下,图片(共20张):先是按友盟的账号进行微信聊天(1、2、3、4)微信朋友圈(5、6、7)收藏(8、9)三个功能测试的,

接着测试了QQ(10、11、12) QQ 空间(13、14),接着换为自己的账号进行微博测试(15、16),微信(17、18、19)、微信朋友圈(20)

swift3.0友盟分享相关推荐

  1. WP8 中使用HTML Agility Pack与友盟分享SDK遇到的 System.Xml.XPath加载问题

    今晚在尝试使用友盟最新的社交分享SDK时,按照官方Demo,并未做多少多少改动,就是去除了对微信.脸书和推特的分享.然后运行之后就一直报错 : {System.IO.FileLoadException ...

  2. Android 友盟统计 友盟推送 友盟分享快速集成

    一.友盟统计 1.首先需要到友盟官网 http://mobile.umeng.com/apps注册并且添加新应用,获得Appkey 2.导入SDK,新版SDK支持Android 6.0,http:// ...

  3. 新版本友盟分享集成的几点注意事项

    在iOS开发中,社交分享已经是一个常见的功能.当我们需要快速集成多个平台的分享时,一般会选择一些第三方的分享平台,例如友盟分享.友盟分享经过多年的发展,现在推出了新版SDK6.1.相比之前的版本,新版 ...

  4. android友盟分享图标是英文,GitHub - GDMiao/UmengEnclosed: 友盟分享二次封装,现有文字分享、图片分享、网页分享等多种分享功能。...

    对友盟分享(Umeng-Share)的功能封装 引言 本文档针对友盟分享(6.9.0)进行了功能封装,完成的对于 文字.图片.网页 分享功能封装,如有其它封装要求请根据本文档的封装思路和友盟分享 ap ...

  5. 【无限互联】集成友盟分享SDK

    集成友盟分享SDK: 友盟注册:http://www.umeng.com/users/sign_up 注册之后登陆账号,点击"添加新应用"完成新应用填写之后,将进入应用管理页面.在 ...

  6. ios 分享功能 集成友盟分享

    1.集成友盟分享,需要先注册一个友盟账号,注册地址 友盟开发者平台官网  友盟集成文档 友盟sdk下载地址友盟sdk下载地址 2,成功下载sdk集成后,微信分享需要配置一下 新浪微博 之类到同样配置就 ...

  7. iOS友盟分享成功不走回调

    友盟分享成功回调方法不执行[-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response;]昨天 ...

  8. 友盟分享插件 for Flutter

    flutter_umeng_ushare 友盟分享插件 for Flutter flutter_umeng_ushare 说明: 在最近的实际项目中测试并使用了该库,目前当前库添加了常用的微博.qq. ...

  9. 自定义友盟分享界面iOS

    提要: 使用代码实现友盟分享弹出的选择界面的自定义方法,不同的按钮实现相应的第三方分享. 1.项目需求 1.1.1:下面是我们项目的需求图:(如果用原生的是一行四个按钮) 1.1.2:友盟注册,以及S ...

最新文章

  1. Python 之 Pandas (一)介绍
  2. 在windows XP运行3660路由器仿真器
  3. js实现响应式瀑布流
  4. CentOS中的中文乱码问题的解决
  5. catia将板环形弯成圆_3.4.3-Catia变换之圆形阵列命令
  6. 一个DataGridView辅助类
  7. JDK8新特性(十二)之并行的Stream流
  8. 剑指Offer之二叉树的后序遍历序列
  9. 教你如何与电脑病毒打游击
  10. 2018年第十三届中国Linux内核开发者大会(CLK)征稿启事
  11. 谷歌搜索引擎优化(谷歌seo)怎么做?
  12. 上传Excel到HBase数据库(POI、poi-ooxml)
  13. 自己推荐的经典好书展示(计算机、企业管理学、生存)
  14. Godaddy网站SSL证书安装
  15. regedit.exe的命令行使用
  16. linux进程家族树,linux下用c语言创建进程树
  17. 360奇舞团钟恒:选用Vue.js进行组件化开发,我们遇到了哪些坑?
  18. Linux引导过程和GRUB引导器
  19. linux 安装软件 垃圾,Ubuntu 18.04 安装垃圾清理工具 BleachBit 2.2
  20. ubuntu上打开md文件_Linux_查看.md

热门文章

  1. 如何得到数据库中所有表字段及字段中文描述
  2. 文件上传的实现(C#)
  3. MFC系统托盘的实现
  4. 【Go】Go基础(二):学习网址汇总
  5. pjax php,ZBlogPHP简单实现pjax的一种方法
  6. java object finalize_Java Object finalize() 方法
  7. settimeout需要清除吗_【期刊导读】新证据:HBsAg水平极低的非活动性HBsAg携带者经聚乙二醇干扰素治疗24周, HBsAg清除率高达83.3%...
  8. Java项目:银行管理系统+文档Java基础Gui(java+Gui)
  9. php mysql环境搭配_centos6.7下搭配apache php mysql环境
  10. 【二级java】二叉树序列