swift3.0友盟分享

news/2024/7/2 23:26:17

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

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

微博

1577306477

b1f0cd8cd2140c407a8c20c319155df8

QQ

1105839186

CKFSBH6Fw21RN5pu

微信

wxd795d58c78ac222b

779c58188ca57046f76353ea1e84412c

代码如下

[objc] view plaincopy
在CODE上查看代码片派生到我的代码片
  1. //  
  2. //  AppDelegate.swift  
  3. //  umengtest  
  4. //  
  5. //  Created by targetcloud on 2016/11/21.  
  6. //  Copyright © 2016年 targetcloud. All rights reserved.  
  7. //  
  8.   
  9. import UIKit  
  10.   
  11. @UIApplicationMain  
  12. class AppDelegate: UIResponder, UIApplicationDelegate {  
  13.   
  14.     var window: UIWindow?  
  15.   
  16.     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {  
  17.           
  18.         UMSocialManager.default().openLog(true)  
  19.         UMSocialManager.default().umSocialAppkey = "57b432afe0f55a9832001a0a"  
  20. //        UMSocialManager.default().umSocialAppkey = "5832b93b99f0c74ef10019c8"  
  21.         print("UMeng social version:\(UMSocialGlobal.umSocialSDKVersion())" );  
  22.           
  23.         UMSocialManager.default().setPlaform(UMSocialPlatformType.wechatSession, appKey"wxdc1e388c3822c80b", appSecret"3baf1193c85774b3fd9d18447d76cab0", redirectURL"http://mobile.umeng.com/social")  
  24. //        UMSocialManager.default().setPlaform(UMSocialPlatformType.wechatSession, appKey: "wxd795d58c78ac222b", appSecret: "779c58188ca57046f76353ea1e84412c", redirectURL: "http://mobile.umeng.com/social")  
  25.         UMSocialManager.default().setPlaform(UMSocialPlatformType.QQ, appKey"100424468", appSecret: nil, redirectURL"http://mobile.umeng.com/social")  
  26. //        UMSocialManager.default().setPlaform(UMSocialPlatformType.QQ, appKey: "1105839186", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")  
  27.         UMSocialManager.default().setPlaform(UMSocialPlatformType.alipaySession, appKey"2015111700822536", appSecret: nil, redirectURL"http://mobile.umeng.com/social")  
  28.         UMSocialManager.default().setPlaform(UMSocialPlatformType.yixinSession, appKey"yx35664bdff4db42c2b7be1e29390c1a06", appSecret: nil, redirectURL"http://mobile.umeng.com/social")  
  29.         UMSocialManager.default().setPlaform(UMSocialPlatformType.laiWangSession, appKey"8112117817424282305", appSecret"9996ed5039e641658de7b83345fee6c9", redirectURL"http://mobile.umeng.com/social")  
  30.         UMSocialManager.default().setPlaform(UMSocialPlatformType.sina, appKey"3921700954", appSecret"04b48b094faeb16683c32669824ebdad", redirectURL"http://sns.whalecloud.com/sina2/callback")  
  31. //        UMSocialManager.default().setPlaform(UMSocialPlatformType.sina, appKey: "1577306477", appSecret: "b1f0cd8cd2140c407a8c20c319155df8", redirectURL: "http://sns.whalecloud.com/sina2/callback")  
  32.         UMSocialManager.default().setPlaform(UMSocialPlatformType.linkedin, appKey"81t5eiem37d2sc", appSecret"7dgUXPLH8kA8WHMV", redirectURL"https://api.linkedin.com/v1/people")  
  33.         UMSocialManager.default().setPlaform(UMSocialPlatformType.twitter, appKey"fB5tvRpna1CKK97xZUslbxiet", appSecret"YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K", redirectURL: nil)  
  34.         UMSocialManager.default().setPlaform(UMSocialPlatformType.facebook, appKey"506027402887373", appSecret: nil, redirectURL"http://www.umeng.com/social")  
  35.         UMSocialManager.default().setPlaform(UMSocialPlatformType.pinterest, appKey"4864546872699668063", appSecret: nil, redirectURL: nil)  
  36.   
  37. //        UMSocialManager.default().removePlatformProvider(withPlatformTypes: [UMSocialPlatformType.wechatFavorite,UMSocialPlatformType.yixinTimeLine,UMSocialPlatformType.laiWangTimeLine,UMSocialPlatformType.qzone])  
  38.         return true  
  39.     }  
  40.       
  41.     func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {  
  42.         let result = UMSocialManager.default().handleOpen(url)  
  43.         if !result{  
  44.               
  45.         }  
  46.         return result  
  47.     }  
  48.       
  49.     func application(_ application: UIApplication, handleOpen url: URL) -> Bool {  
  50.         let result = UMSocialManager.default().handleOpen(url)  
  51.         if !result{  
  52.               
  53.         }  
  54.         return result  
  55.     }  
  56. }  

[objc] view plaincopy
在CODE上查看代码片派生到我的代码片
  1. //  
  2. //  ViewController.swift  
  3. //  umengtest  
  4. //  
  5. //  Created by targetcloud on 2016/11/21.  
  6. //  Copyright © 2016年 targetcloud. All rights reserved.  
  7. //  
  8.   
  9. import UIKit  
  10.   
  11. class ViewController: UIViewController {  
  12.   
  13.     override func viewDidLoad() {  
  14.         super.viewDidLoad()  
  15.           
  16.         let shareButton:UIButton = UIButton(frame: CGRect(x: 50, y50, width200, height50))  
  17. //        shareButton.center = CGPoint(x: self.view.frame.size.width / 2, y: self.view.frame.size.height / 2)  
  18.         shareButton.setTitle("Swift图文分享", for: UIControlState())  
  19.         shareButton.addTarget(self, action: #selector(shareAction_pic), for: UIControlEvents.touchUpInside)  
  20.         shareButton.setTitleColor(UIColor.blue, for: UIControlState())  
  21.         shareButton.backgroundColor = UIColor.clear  
  22.           
  23.         let sharewww : UIButton = UIButton(frame: CGRect(x: 50, y100, width200, height50))  
  24.         sharewww.setTitle("Swift网页分享", for: UIControlState())  
  25.         sharewww.addTarget(self, action: #selector(shareAction_www), for: UIControlEvents.touchUpInside)  
  26.         sharewww.setTitleColor(UIColor.blue, for: UIControlState())  
  27.         sharewww.backgroundColor = UIColor.clear  
  28.           
  29.         let sharetxt : UIButton = UIButton(frame: CGRect(x: 50, y150, width200, height50))  
  30.         sharetxt.setTitle("Swift文字分享", for: UIControlState())  
  31.         sharetxt.addTarget(self, action: #selector(shareAction_txt), for: UIControlEvents.touchUpInside)  
  32.         sharetxt.setTitleColor(UIColor.blue, for: UIControlState())  
  33.         sharetxt.backgroundColor = UIColor.clear  
  34.           
  35.         let shareMusic : UIButton = UIButton(frame: CGRect(x: 50, y200, width200, height50))  
  36.         shareMusic.setTitle("Swift音乐分享", for: UIControlState())  
  37.         shareMusic.addTarget(self, action: #selector(shareAction_music), for: UIControlEvents.touchUpInside)  
  38.         shareMusic.setTitleColor(UIColor.blue, for: UIControlState())  
  39.         shareMusic.backgroundColor = UIColor.clear  
  40.           
  41.         let shareVideo : UIButton = UIButton(frame: CGRect(x: 50, y250, width200, height50))  
  42.         shareVideo.setTitle("Swift视频分享", for: UIControlState())  
  43.         shareVideo.addTarget(self, action: #selector(shareAction_video), for: UIControlEvents.touchUpInside)  
  44.         shareVideo.setTitleColor(UIColor.blue, for: UIControlState())  
  45.         shareVideo.backgroundColor = UIColor.clear  
  46.           
  47.         self.view.addSubview(shareButton)  
  48.         self.view.addSubview(sharewww)  
  49.         self.view.addSubview(sharetxt)  
  50.         self.view.addSubview(shareMusic)  
  51.         self.view.addSubview(shareVideo)  
  52.     }  
  53.   
  54.     func shareAction_pic (){  
  55.         UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shreMenuView, platformType) in  
  56.             let messageObject:UMSocialMessageObject = UMSocialMessageObject.init()  
  57.             messageObject.text = "友盟分享测试(图片),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"  
  58.             let shareObject:UMShareImageObject = UMShareImageObject.init()  
  59.             shareObject.title = "图片分享"  
  60.             shareObject.descr = "这里是图片分享测试,作者:targetcloud"  
  61.             shareObject.thumbImage = UIImage.init(named: "icon")  
  62.             shareObject.shareImage = "http://dev.umeng.com/images/tab2_1.png"  
  63.             messageObject.shareObject = shareObject;  
  64.             UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewControllerself, completion: { (shareResponse, error) in  
  65.                 if error != nil {  
  66.                     print("Share Fail with error :%@", error)  
  67.                 }else{  
  68.                     self?.getUserInfoForPlatform(platformType: platformType)  
  69.                     print("Share succeed")  
  70.                 }  
  71.             })  
  72.         }  
  73.     }  
  74.       
  75.     func shareAction_www (){  
  76.         UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shreMenuView, platformType) in  
  77.             let messageObject:UMSocialMessageObject = UMSocialMessageObject.init()  
  78.             messageObject.text = "友盟分享测试(网页),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"  
  79.             let shareObject:UMShareWebpageObject = UMShareWebpageObject.init()  
  80.             shareObject.title = "网页分享"  
  81.             shareObject.descr = "这里是网页分享测试,作者:targetcloud"  
  82.             shareObject.thumbImage = UIImage.init(named: "icon")  
  83.             shareObject.webpageUrl = "http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html"  
  84.             messageObject.shareObject = shareObject;  
  85.             UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewControllerself, completion: { (shareResponse, error) in  
  86.                 if error != nil {  
  87.                     print("Share Fail with error :%@", error)  
  88.                 }else{  
  89.                     self?.getUserInfoForPlatform(platformType: platformType)  
  90.                     print("Share succeed")  
  91.                 }  
  92.             })  
  93.         }  
  94.     }  
  95.       
  96.     func shareAction_txt (){  
  97.         UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in  
  98.             let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()  
  99.             messageObject.text = "友盟分享测试(文本),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"  
  100.             UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewControllerself, completion: { (data:Any?, error:Error?) in  
  101.                 if error != nil {  
  102.                     print("************Share fail with error *********",error)  
  103.                 }else{  
  104.                     UMSocialManager.default().getUserInfo(with: platformType, currentViewControllerself, completion: { (result:Any?, error:Error?) in  
  105.                         if let userinfo  = result as? UMSocialUserInfoResponse{  
  106.                             let message = " name: \(userinfo.name)\n icon: \(userinfo.iconurl)\n gender: \(userinfo.gender)\n"  
  107.                             print(message)  
  108.                         }  
  109.                     })  
  110.                     if let resp:UMSocialShareResponse = data as? UMSocialShareResponse  {  
  111.                         print("response message is ",resp.message ?? "")  
  112.                         print("response originalResponse data is ",resp.originalResponse ?? "")  
  113.                     }  
  114.                     print("response data is ",data)  
  115.                 }  
  116.                 self?.alertWithError(error: error)  
  117.             })  
  118.         }  
  119.     }  
  120.       
  121.     func shareAction_music (){  
  122.         UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in  
  123.             let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()  
  124.             messageObject.text = "友盟分享测试(音乐),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"  
  125.             let shareObject:UMShareMusicObject = UMShareMusicObject.init()  
  126.             shareObject.title = "音乐分享"  
  127.             shareObject.descr = "这里是音乐分享测试,作者:targetcloud"  
  128.             shareObject.thumbImage = UIImage.init(named: "icon")  
  129.             shareObject.musicUrl = "http://c.y.qq.com/v8/playsong.html?songid=108782194&source=yqq#wechat_redirect"  
  130.             messageObject.shareObject = shareObject;  
  131.             UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewControllerself, completion: { (data:Any?, error:Error?) in  
  132.                 if error != nil {  
  133.                     print("************Share fail with error *********",error)  
  134.                 }else{  
  135.                     if let resp:UMSocialShareResponse = data as? UMSocialShareResponse  {  
  136.                         print("response message is ",resp.message ?? "")  
  137.                         print("response originalResponse data is ",resp.originalResponse ?? "")  
  138.                     }  
  139.                     print("response data is ",data)  
  140.                 }  
  141.                 self?.alertWithError(error: error)  
  142.             })  
  143.         }  
  144.     }  
  145.       
  146.     func shareAction_video (){  
  147.         UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in  
  148.             let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()  
  149.             messageObject.text = "友盟分享测试(视频),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"  
  150.             let shareObject:UMShareVideoObject = UMShareVideoObject.init()  
  151.             shareObject.title = "视频分享"  
  152.             shareObject.descr = "这里是视频分享测试,作者:targetcloud"  
  153.             shareObject.thumbImage = UIImage.init(named: "icon")  
  154.             shareObject.videoUrl = "http://v.youku.com/v_show/id_XMTgyMjI1MjQxNg==.html?f=18252872#paction"  
  155.             messageObject.shareObject = shareObject;  
  156.             UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewControllerself, completion: { (data:Any?, error:Error?) in  
  157.                 if error != nil {  
  158.                     print("************Share fail with error *********",error)  
  159.                 }else{  
  160.                     if let resp:UMSocialShareResponse = data as? UMSocialShareResponse  {  
  161.                         print("response message is ",resp.message ?? "")  
  162.                         print("response originalResponse data is ",resp.originalResponse ?? "")  
  163.                     }  
  164.                     print("response data is ",data)  
  165.                 }  
  166.                 self?.alertWithError(error: error)  
  167.             })  
  168.         }  
  169.     }  
  170.       
  171.     func alertWithError(error:Error?){  
  172.         var result = ""  
  173.         if (error == nil) {  
  174.             result = "恭喜你,分享成功!邀请好友一起玩吧!"  
  175.         }else{  
  176.             if(error != nil){  
  177.                 result = "分享失败,此功能正在努力开通中..."  
  178.             }else{  
  179.                 result = "额,分享失败了!"  
  180.             }  
  181.         }  
  182.         let alert = UIAlertView.init(title: "越分享,越快乐!", message: result, delegate: nil, cancelButtonTitle: NSLocalizedString("确定", comment"确定"))  
  183.         alert.show()  
  184.     }  
  185.       
  186.     func getUserInfoForPlatform(platformType:UMSocialPlatformType){  
  187.         UMSocialManager.default().getUserInfo(with: platformType, currentViewControllerself, completion: { (result:Any?, error:Error?) in  
  188.             if let userinfo  = result as? UMSocialUserInfoResponse {  
  189.                 let message = " name: \(userinfo.name)\n icon: \(userinfo.iconurl)\n gender: \(userinfo.gender)\n"  
  190.                 print(message)  
  191.                 let alert = UIAlertView.init(title: "UserInfo", message: message, delegate: nil, cancelButtonTitle: NSLocalizedString("确定", comment"确定"))  
  192.                 alert.show()  
  193.             }  
  194.         })  
  195.     }  
  196.   
  197. }  




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

运行效果如下,图片(共20张):先是按友盟的账号进行微信聊天(1234微信朋友圈(567)收藏(89)三个功能测试的,

接着测试了QQ101112 QQ 空间(1314),接着换为自己的账号进行微博测试(1516),微信(171819)、微信朋友圈(20





















http://lihuaxi.xjx100.cn/news/235260.html

相关文章

HTTP 2.0与OkHttp

HTTP 2.0是对1.x的扩展而非替代,之所以是“2.0”,是因为它改变了客户端与服务器之间交换数据的方式。HTTP 2.0增加了新的二进制分帧数据层,而这一层并不兼容之前的HTTP 1.x服务器及客户端——是谓2.0。  在正式介绍HTTP 2.0之前,…

ZYKeyboardUtil 让键盘遮盖事件处理变得得心应手

Demo地址:https://github.com/liuzhiyi1992/ZYKeyboardUtil 键盘遮盖输入控件或按钮在日常app开发中避之不及,考虑各种情况下UI各种嵌套,最后还要注册监听再获取指定键盘信息。我们可以通过键盘处理工具类ZYKeyboardUtil避繁就简&#xff0c…

swift3.0三种反向传值

一 :通知 1.通知传值所用方法 // MARK: - private methods(内部接口) let NotifMycation NSNotification.Name(rawValue:"MyNSNotification") func tempbuttonAction() { //这个方法可以传一个值 NotificationCenter.default.post(name: NotifMycation, object: &q…

极光推送集成步骤详解

关于极光推送,本人也算做过几次,下面就给大家简单总结下我做时所遇到的问题。下面这个文件,需要你先导入极光SDK后才能调试,需要注意的是,极光推送不支持模拟器,所以需要真机调试,因此首先要做的…

【Python3爬虫】常见反爬虫措施及解决办法(二) ...

【Python3爬虫】常见反爬虫措施及解决办法(二) 这一篇博客,还是接着说那些常见的反爬虫措施以及我们的解决办法。同样的,如果对你有帮助的话,麻烦点一下推荐啦。 一、防盗链 这次我遇到的防盗链,除了前面说…

Swift3.0和OC桥接方法

1.直接在工程中commandn,出现如图,点击Header File创建桥接文件Bridging-Header.h,如图: 2.点击next,出现如图画面,一定要记得勾选第一项,再点击create创建完成。 3.配置桥接文件,点击target - …

2019年3月

分包加载 使用公众号登录微信提示  "公众号暂不支持此种登录方式" 使用已经注册过的手机号注册新的微信账号提示  "你申请注册的手机号已被其他微信号绑定,暂时不能使用该手机号注册" https://github.com/witcat/LayaWxCacheFromZip /******/ (functio…

JSPatch – 动态更新iOS APP

JSPatch是最近业余做的项目,只需在项目中引入极小的引擎,就可以使用JavaScript调用任何Objective-C的原生接口,获得脚本语言的能力:动态更新APP,替换项目原生代码修复bug。 用途 是否有过这样的经历:新版本…