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)
相关文章:

C++11中std::future的使用
C11中的std::future是一个模板类。std::future提供了一种用于访问异步操作结果的机制。std::future所引用的共享状态不能与任何其它异步返回的对象共享(与std::shared_future相反)( std::future references shared state that is not shared with any other asynchronous retur…
给算法工程师和研究员的「霸王餐」| 附招聘信息
现在的算法工程师真的是太难了!要让AI会看人眼都分辨不清的医疗影像!数据又不够,还得用前沿技术!好不容易学会看片,还要让AI会分析病理!然后模型搞出来了,还要把几十种模型,做N次计算…

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

C++11中std::shared_future的使用
C11中的std::shared_future是个模板类。与std::future类似,std::shared_future提供了一种访问异步操作结果的机制;不同于std::future,std::shared_future允许多个线程等待同一个共享状态;不同于std::future仅支持移动操作…
聊聊抖音、奈飞、Twitch、大疆、快手、B站的多媒体关键技术
随着5G牌照发放,5G终端正在迎来集中上市潮,对于5G带来的变革一触即发。目前互联网上超过七成的流量来自多媒体,未来这个比例将超过八成。音视频就像空气和水一样普及,深度到每个人的生活和工作中。同时,深度学习技术则…

Linux安全事件应急响应排查方法总结
Linux安全事件应急响应排查方法总结 Linux是服务器操作系统中最常用的操作系统,因为其拥有高性能、高扩展性、高安全性,受到了越来越多的运维人员追捧。但是针对Linux服务器操作系统的安全事件也非常多的。攻击方式主要是弱口令攻击、远程溢出攻击及其他…

C++11中std::packaged_task的使用
C11中的std::packaged_task是个模板类。std::packaged_task包装任何可调用目标(函数、lambda表达式、bind表达式、函数对象)以便它可以被异步调用。它的返回值或抛出的异常被存储于能通过std::future对象访问的共享状态中。 std::packaged_task类似于std::function,…

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

量子算命,在线掷筊:一个IBM量子云计算机的应用实践,代码都有了
整理 | Jane 出品| AI科技大本营(ID:rgznai100) “算命”,古今中外,亘古不衰的一门学问,哪怕到了今天,大家对算命占卜都抱着一些”敬畏“的信任心理,西方流行塔罗牌,国…

rails应用ajax之二:使用rails自身支持
考虑另一种情况: 1. 页面上半部分显示当前的所有用户,页面下半部分是输入新用户的界面; 2. 每当输入新用户时,页面上半部分会动态更新新加用户的内容; 我们还是用ajax实现,不过这次用rails内部对ajax的支持…

C++11中std::async的使用
C11中的std::async是个模板函数。std::async异步调用函数,在某个时候以Args作为参数(可变长参数)调用Fn,无需等待Fn执行完成就可返回,返回结果是个std::future对象。Fn返回的值可通过std::future对象的get成员函数获取。一旦完成Fn的执行&…
BAT数据披露:缺人!110万AI人才缺口,两者矛盾,凉凉了!
人工智能到底有多火?近日国内首份《BAT人工智能领域人才发展报告》新鲜出炉,此次报告是针对国内人工智能领域的人才争夺情况进行了梳理。并把研究对象锁定在BAT三大巨头的身上。来源:《BAT人工智能领域人才发展报告》其中得出最为核心的结论&…

swift3.0最新拨打电话方法
let alertVC : UIAlertController UIAlertController.init(title: "是否拨打报警电话:10086", message: "", preferredStyle: .alert) let falseAA : UIAlertAction UIAlertAction.init(title: "取消", style: .cancel, handler: nil) let tr…

关于手机已处理里重复单据的处理办法
更新视图 VWFE_TASK去掉 union TWFE_TASK_BAK 的部分,原因是因为后面做了流程预演导致的问题转载于:https://blog.51cto.com/iderun/1602828

swiftswift3.0自己封装的快速构建页面的方法
//#param mark 控件 func creatLabel(frame:CGRect,text:String,textColor:UIColor,textFont:CGFloat,textAlignment:NSTextAlignment) -> UILabel { let label UILabel.init(frame: frame) label.text text label.textColor textColor label.font UIFont.systemFont(of…
Google是如何做Code Review的?| CSDN原力计划
作者 | 帅昕 xindoo 编辑 | 屠敏出品 | CSDN 博客我和几个小伙伴一起翻译了Google前一段时间放出来的Google’s Engineering Practices documentation(https://github.com/google/eng-practices),翻译后的GitHub仓库:https://gith…

从FFmpeg 4. 2源码中提取dshow mjpeg code步骤
之前在https://blog.csdn.net/fengbingchun/article/details/103735560 中介绍过在Windows上通过vs2017编译FFmpeg源码进行单步调试的步骤,为了进一步熟悉FFmpeg这里以提取FFmpeg dshow mjpeg源码为例介绍其实现过程及注意事项: FFmpeg是用C实现的&…

ControlButton按钮事件
#ifndef __HControlButton_H__#define __HControlButton_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT; //用于标识当前按钮的状态typedef enum{ touch_begin, touch_down, touch_up,}tagForTouch;class HControlB…

swift3.0UIAlertController使用方法
let alertVC : UIAlertController UIAlertController.init(title: "添加照片", message: "", preferredStyle: .actionSheet) let cleanAction UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel,handler:nil) let photoActi…

Doxygen使用介绍
Doxygen的主页为http://doxygen.nl/,它的license为GPL,最新发布版本为1.8.17,源代码存放在https://github.com/doxygen/doxygen,它支持的语言包括C、C、Objective-C、C#、Java、Python等,它支持的系统平台包括Winodws、…
云计算软件生态圈:摸到一把大牌
作者 | 老姜编辑 | 阿秃出品 | CSDN云计算(ID:CSDNcloud)“我觉得我摸着了一把大牌。”软件领域的新锐企业——有赞公司创始人兼CEO白鸦在转向SaaS领域的一个细分市场时,曾对天使投资人这样说。而老牌软件企业金蝶创始人徐少春在2…

iOS封装HTTPS双向和单向验证
1.HttpsUtil (1) 对双向和单向验证的封装 #import <Foundation/Foundation.h> #import "AFNetworking.h" interface HttpsUtil : NSObject // 双向认证 (void)configHTTPSessionManager:(AFHTTPSessionManager *)manager serverCers:(NSArray *) serverCerNam…

开源库BearSSL介绍及使用
BearSSL是用C语言实现的SSL/TLS协议,它的源码可直接通过git clone https://www.bearssl.org/git/BearSSL 下载,它的license是MIT,最新版本为0.6。 BearSSL的主要特性是: (1). 正确且安全:对不安全的协议版本和算法选…
个推CTO安森:我所理解的数据中台
作者 | 个推CTO安森来源 | 个推技术学院(ID:ID: getuitech)引言在前面两篇文章(《数据智能时代来临:本质及技术体系要求》和《多维度分析系统的选型方法》)之中,我们概括性地阐述了对于数据智能的理解&…

玩弹珠手游-杂想
前言 为什么会写这个杂想呢? 因为最近这一个月来,我有点太沉迷怪物弹珠这个游戏了,每天下班回来的时间和上下班路途都在玩这个游戏,占据了我大部分的业余时间,也该是时候放一放玩游戏了。 为什么会玩这个游戏呢&#x…

OC封装时间选择器
#import <UIKit/UIKit.h> protocol TimeDatePickerViewDelegate <NSObject> //必须实现的两个协议 required - (void)changeTime : (NSDate *)date;//当时改变时出发 - (void)daterMine : (NSDate *)date;//更确定时间 end interface TimeDatePickerView :UIView /…
银行卡大小的充电宝,买就送耳机!
每个人的朋友圈和微博上似乎都有那么几个活得让人羡慕的朋友他们的生活看起来不仅精致,还很丰富多彩从早上第一刻就开始了↓出门旅游新一天的穿搭逆天朋友团咖啡馆到书店逼格十足的日料夜景太迷人忍不住发个小视频最后一定不要错过傍晚的夕阳,真的好上镜…

C++中插件使用举例
插件并不是在构建时链接的,而是在运行时发现并加载的。因此,用户可以利用你定义好的插件API来编写自己的插件。这样他们就能以指定方式扩展API的功能。插件库是一个动态库,它可以独立于核心API编译,在运行时根据需要显示加载。不过…

C和C++安全编码笔记:指针诡计
指针诡计(pointer subterfuge)是通过修改指针值来利用程序漏洞的方法的统称。 可以通过覆盖函数指针将程序的控制权转移到攻击者提供的外壳代码(shellcode)。当程序通过函数指针执行一个函数调用时,攻击者提供的代码将会取代原本希望执行的代码而得到执行。 对象指…