swift3.0友盟分享
经过(一)的讲解,大家应该可以按照友盟提供的测试账号可以集成友盟分享了,友盟目前集合了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
1105839186
CKFSBH6Fw21RN5pu
微信
wxd795d58c78ac222b
779c58188ca57046f76353ea1e84412c
代码如下
- //
- // AppDelegate.swift
- // umengtest
- //
- // Created by targetcloud on 2016/11/21.
- // Copyright © 2016年 targetcloud. All rights reserved.
- //
- import UIKit
- @UIApplicationMain
- class AppDelegate: UIResponder, UIApplicationDelegate {
- var window: UIWindow?
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
- UMSocialManager.default().openLog(true)
- UMSocialManager.default().umSocialAppkey = "57b432afe0f55a9832001a0a"
- // UMSocialManager.default().umSocialAppkey = "5832b93b99f0c74ef10019c8"
- print("UMeng social version:\(UMSocialGlobal.umSocialSDKVersion())" );
- UMSocialManager.default().setPlaform(UMSocialPlatformType.wechatSession, appKey: "wxdc1e388c3822c80b", appSecret: "3baf1193c85774b3fd9d18447d76cab0", redirectURL: "http://mobile.umeng.com/social")
- // UMSocialManager.default().setPlaform(UMSocialPlatformType.wechatSession, appKey: "wxd795d58c78ac222b", appSecret: "779c58188ca57046f76353ea1e84412c", redirectURL: "http://mobile.umeng.com/social")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.QQ, appKey: "100424468", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
- // UMSocialManager.default().setPlaform(UMSocialPlatformType.QQ, appKey: "1105839186", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.alipaySession, appKey: "2015111700822536", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.yixinSession, appKey: "yx35664bdff4db42c2b7be1e29390c1a06", appSecret: nil, redirectURL: "http://mobile.umeng.com/social")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.laiWangSession, appKey: "8112117817424282305", appSecret: "9996ed5039e641658de7b83345fee6c9", redirectURL: "http://mobile.umeng.com/social")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.sina, appKey: "3921700954", appSecret: "04b48b094faeb16683c32669824ebdad", redirectURL: "http://sns.whalecloud.com/sina2/callback")
- // UMSocialManager.default().setPlaform(UMSocialPlatformType.sina, appKey: "1577306477", appSecret: "b1f0cd8cd2140c407a8c20c319155df8", redirectURL: "http://sns.whalecloud.com/sina2/callback")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.linkedin, appKey: "81t5eiem37d2sc", appSecret: "7dgUXPLH8kA8WHMV", redirectURL: "https://api.linkedin.com/v1/people")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.twitter, appKey: "fB5tvRpna1CKK97xZUslbxiet", appSecret: "YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K", redirectURL: nil)
- UMSocialManager.default().setPlaform(UMSocialPlatformType.facebook, appKey: "506027402887373", appSecret: nil, redirectURL: "http://www.umeng.com/social")
- UMSocialManager.default().setPlaform(UMSocialPlatformType.pinterest, appKey: "4864546872699668063", appSecret: nil, redirectURL: nil)
- // UMSocialManager.default().removePlatformProvider(withPlatformTypes: [UMSocialPlatformType.wechatFavorite,UMSocialPlatformType.yixinTimeLine,UMSocialPlatformType.laiWangTimeLine,UMSocialPlatformType.qzone])
- return true
- }
- func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
- let result = UMSocialManager.default().handleOpen(url)
- if !result{
- }
- return result
- }
- func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
- let result = UMSocialManager.default().handleOpen(url)
- if !result{
- }
- return result
- }
- }
- //
- // ViewController.swift
- // umengtest
- //
- // Created by targetcloud on 2016/11/21.
- // Copyright © 2016年 targetcloud. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- let shareButton:UIButton = UIButton(frame: CGRect(x: 50, y: 50, width: 200, height: 50))
- // shareButton.center = CGPoint(x: self.view.frame.size.width / 2, y: self.view.frame.size.height / 2)
- shareButton.setTitle("Swift图文分享", for: UIControlState())
- shareButton.addTarget(self, action: #selector(shareAction_pic), for: UIControlEvents.touchUpInside)
- shareButton.setTitleColor(UIColor.blue, for: UIControlState())
- shareButton.backgroundColor = UIColor.clear
- let sharewww : UIButton = UIButton(frame: CGRect(x: 50, y: 100, width: 200, height: 50))
- sharewww.setTitle("Swift网页分享", for: UIControlState())
- sharewww.addTarget(self, action: #selector(shareAction_www), for: UIControlEvents.touchUpInside)
- sharewww.setTitleColor(UIColor.blue, for: UIControlState())
- sharewww.backgroundColor = UIColor.clear
- let sharetxt : UIButton = UIButton(frame: CGRect(x: 50, y: 150, width: 200, height: 50))
- sharetxt.setTitle("Swift文字分享", for: UIControlState())
- sharetxt.addTarget(self, action: #selector(shareAction_txt), for: UIControlEvents.touchUpInside)
- sharetxt.setTitleColor(UIColor.blue, for: UIControlState())
- sharetxt.backgroundColor = UIColor.clear
- let shareMusic : UIButton = UIButton(frame: CGRect(x: 50, y: 200, width: 200, height: 50))
- shareMusic.setTitle("Swift音乐分享", for: UIControlState())
- shareMusic.addTarget(self, action: #selector(shareAction_music), for: UIControlEvents.touchUpInside)
- shareMusic.setTitleColor(UIColor.blue, for: UIControlState())
- shareMusic.backgroundColor = UIColor.clear
- let shareVideo : UIButton = UIButton(frame: CGRect(x: 50, y: 250, width: 200, height: 50))
- shareVideo.setTitle("Swift视频分享", for: UIControlState())
- shareVideo.addTarget(self, action: #selector(shareAction_video), for: UIControlEvents.touchUpInside)
- shareVideo.setTitleColor(UIColor.blue, for: UIControlState())
- shareVideo.backgroundColor = UIColor.clear
- self.view.addSubview(shareButton)
- self.view.addSubview(sharewww)
- self.view.addSubview(sharetxt)
- self.view.addSubview(shareMusic)
- self.view.addSubview(shareVideo)
- }
- func shareAction_pic (){
- UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shreMenuView, platformType) in
- let messageObject:UMSocialMessageObject = UMSocialMessageObject.init()
- messageObject.text = "友盟分享测试(图片),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
- let shareObject:UMShareImageObject = UMShareImageObject.init()
- shareObject.title = "图片分享"
- shareObject.descr = "这里是图片分享测试,作者:targetcloud"
- shareObject.thumbImage = UIImage.init(named: "icon")
- shareObject.shareImage = "http://dev.umeng.com/images/tab2_1.png"
- messageObject.shareObject = shareObject;
- UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (shareResponse, error) in
- if error != nil {
- print("Share Fail with error :%@", error)
- }else{
- self?.getUserInfoForPlatform(platformType: platformType)
- print("Share succeed")
- }
- })
- }
- }
- func shareAction_www (){
- UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shreMenuView, platformType) in
- let messageObject:UMSocialMessageObject = UMSocialMessageObject.init()
- messageObject.text = "友盟分享测试(网页),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
- let shareObject:UMShareWebpageObject = UMShareWebpageObject.init()
- shareObject.title = "网页分享"
- shareObject.descr = "这里是网页分享测试,作者:targetcloud"
- shareObject.thumbImage = UIImage.init(named: "icon")
- shareObject.webpageUrl = "http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html"
- messageObject.shareObject = shareObject;
- UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (shareResponse, error) in
- if error != nil {
- print("Share Fail with error :%@", error)
- }else{
- self?.getUserInfoForPlatform(platformType: platformType)
- print("Share succeed")
- }
- })
- }
- }
- func shareAction_txt (){
- UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in
- let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()
- messageObject.text = "友盟分享测试(文本),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
- UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (data:Any?, error:Error?) in
- if error != nil {
- print("************Share fail with error *********",error)
- }else{
- UMSocialManager.default().getUserInfo(with: platformType, currentViewController: self, completion: { (result:Any?, error:Error?) in
- if let userinfo = result as? UMSocialUserInfoResponse{
- let message = " name: \(userinfo.name)\n icon: \(userinfo.iconurl)\n gender: \(userinfo.gender)\n"
- print(message)
- }
- })
- if let resp:UMSocialShareResponse = data as? UMSocialShareResponse {
- print("response message is ",resp.message ?? "")
- print("response originalResponse data is ",resp.originalResponse ?? "")
- }
- print("response data is ",data)
- }
- self?.alertWithError(error: error)
- })
- }
- }
- func shareAction_music (){
- UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in
- let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()
- messageObject.text = "友盟分享测试(音乐),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
- let shareObject:UMShareMusicObject = UMShareMusicObject.init()
- shareObject.title = "音乐分享"
- shareObject.descr = "这里是音乐分享测试,作者:targetcloud"
- shareObject.thumbImage = UIImage.init(named: "icon")
- shareObject.musicUrl = "http://c.y.qq.com/v8/playsong.html?songid=108782194&source=yqq#wechat_redirect"
- messageObject.shareObject = shareObject;
- UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (data:Any?, error:Error?) in
- if error != nil {
- print("************Share fail with error *********",error)
- }else{
- if let resp:UMSocialShareResponse = data as? UMSocialShareResponse {
- print("response message is ",resp.message ?? "")
- print("response originalResponse data is ",resp.originalResponse ?? "")
- }
- print("response data is ",data)
- }
- self?.alertWithError(error: error)
- })
- }
- }
- func shareAction_video (){
- UMSocialUIManager.showShareMenuViewInWindow {[weak self] (shareSelectionView:UMShareMenuSelectionView?, platformType:UMSocialPlatformType) in
- let messageObject : UMSocialMessageObject = UMSocialMessageObject.init()
- messageObject.text = "友盟分享测试(视频),swift3.0 Xcode8.1 umeng6.0.3 作者:targetcloud"
- let shareObject:UMShareVideoObject = UMShareVideoObject.init()
- shareObject.title = "视频分享"
- shareObject.descr = "这里是视频分享测试,作者:targetcloud"
- shareObject.thumbImage = UIImage.init(named: "icon")
- shareObject.videoUrl = "http://v.youku.com/v_show/id_XMTgyMjI1MjQxNg==.html?f=18252872#paction"
- messageObject.shareObject = shareObject;
- UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: self, completion: { (data:Any?, error:Error?) in
- if error != nil {
- print("************Share fail with error *********",error)
- }else{
- if let resp:UMSocialShareResponse = data as? UMSocialShareResponse {
- print("response message is ",resp.message ?? "")
- print("response originalResponse data is ",resp.originalResponse ?? "")
- }
- print("response data is ",data)
- }
- self?.alertWithError(error: error)
- })
- }
- }
- func alertWithError(error:Error?){
- var result = ""
- if (error == nil) {
- result = "恭喜你,分享成功!邀请好友一起玩吧!"
- }else{
- if(error != nil){
- result = "分享失败,此功能正在努力开通中..."
- }else{
- result = "额,分享失败了!"
- }
- }
- let alert = UIAlertView.init(title: "越分享,越快乐!", message: result, delegate: nil, cancelButtonTitle: NSLocalizedString("确定", comment: "确定"))
- alert.show()
- }
- func getUserInfoForPlatform(platformType:UMSocialPlatformType){
- UMSocialManager.default().getUserInfo(with: platformType, currentViewController: self, completion: { (result:Any?, error:Error?) in
- if let userinfo = result as? UMSocialUserInfoResponse {
- let message = " name: \(userinfo.name)\n icon: \(userinfo.iconurl)\n gender: \(userinfo.gender)\n"
- print(message)
- let alert = UIAlertView.init(title: "UserInfo", message: message, delegate: nil, cancelButtonTitle: NSLocalizedString("确定", comment: "确定"))
- alert.show()
- }
- })
- }
- }
集成步骤不再重复,请按照(一)是肯定可以成功集成的
运行效果如下,图片(共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友盟分享相关推荐
- WP8 中使用HTML Agility Pack与友盟分享SDK遇到的 System.Xml.XPath加载问题
今晚在尝试使用友盟最新的社交分享SDK时,按照官方Demo,并未做多少多少改动,就是去除了对微信.脸书和推特的分享.然后运行之后就一直报错 : {System.IO.FileLoadException ...
- Android 友盟统计 友盟推送 友盟分享快速集成
一.友盟统计 1.首先需要到友盟官网 http://mobile.umeng.com/apps注册并且添加新应用,获得Appkey 2.导入SDK,新版SDK支持Android 6.0,http:// ...
- 新版本友盟分享集成的几点注意事项
在iOS开发中,社交分享已经是一个常见的功能.当我们需要快速集成多个平台的分享时,一般会选择一些第三方的分享平台,例如友盟分享.友盟分享经过多年的发展,现在推出了新版SDK6.1.相比之前的版本,新版 ...
- android友盟分享图标是英文,GitHub - GDMiao/UmengEnclosed: 友盟分享二次封装,现有文字分享、图片分享、网页分享等多种分享功能。...
对友盟分享(Umeng-Share)的功能封装 引言 本文档针对友盟分享(6.9.0)进行了功能封装,完成的对于 文字.图片.网页 分享功能封装,如有其它封装要求请根据本文档的封装思路和友盟分享 ap ...
- 【无限互联】集成友盟分享SDK
集成友盟分享SDK: 友盟注册:http://www.umeng.com/users/sign_up 注册之后登陆账号,点击"添加新应用"完成新应用填写之后,将进入应用管理页面.在 ...
- ios 分享功能 集成友盟分享
1.集成友盟分享,需要先注册一个友盟账号,注册地址 友盟开发者平台官网 友盟集成文档 友盟sdk下载地址友盟sdk下载地址 2,成功下载sdk集成后,微信分享需要配置一下 新浪微博 之类到同样配置就 ...
- iOS友盟分享成功不走回调
友盟分享成功回调方法不执行[-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response;]昨天 ...
- 友盟分享插件 for Flutter
flutter_umeng_ushare 友盟分享插件 for Flutter flutter_umeng_ushare 说明: 在最近的实际项目中测试并使用了该库,目前当前库添加了常用的微博.qq. ...
- 自定义友盟分享界面iOS
提要: 使用代码实现友盟分享弹出的选择界面的自定义方法,不同的按钮实现相应的第三方分享. 1.项目需求 1.1.1:下面是我们项目的需求图:(如果用原生的是一行四个按钮) 1.1.2:友盟注册,以及S ...
最新文章
- Python 之 Pandas (一)介绍
- 在windows XP运行3660路由器仿真器
- js实现响应式瀑布流
- CentOS中的中文乱码问题的解决
- catia将板环形弯成圆_3.4.3-Catia变换之圆形阵列命令
- 一个DataGridView辅助类
- JDK8新特性(十二)之并行的Stream流
- 剑指Offer之二叉树的后序遍历序列
- 教你如何与电脑病毒打游击
- 2018年第十三届中国Linux内核开发者大会(CLK)征稿启事
- 谷歌搜索引擎优化(谷歌seo)怎么做?
- 上传Excel到HBase数据库(POI、poi-ooxml)
- 自己推荐的经典好书展示(计算机、企业管理学、生存)
- Godaddy网站SSL证书安装
- regedit.exe的命令行使用
- linux进程家族树,linux下用c语言创建进程树
- 360奇舞团钟恒:选用Vue.js进行组件化开发,我们遇到了哪些坑?
- Linux引导过程和GRUB引导器
- linux 安装软件 垃圾,Ubuntu 18.04 安装垃圾清理工具 BleachBit 2.2
- ubuntu上打开md文件_Linux_查看.md
热门文章
- 如何得到数据库中所有表字段及字段中文描述
- 文件上传的实现(C#)
- MFC系统托盘的实现
- 【Go】Go基础(二):学习网址汇总
- pjax php,ZBlogPHP简单实现pjax的一种方法
- java object finalize_Java Object finalize() 方法
- settimeout需要清除吗_【期刊导读】新证据:HBsAg水平极低的非活动性HBsAg携带者经聚乙二醇干扰素治疗24周, HBsAg清除率高达83.3%...
- Java项目:银行管理系统+文档Java基础Gui(java+Gui)
- php mysql环境搭配_centos6.7下搭配apache php mysql环境
- 【二级java】二叉树序列