目录:[Swift]Xcode实际操作

完成开发包的安装和配置之后,本文将演示社会化分享功能的具体开发步骤。

在项目导航区,打开并编辑程序代理文件【AppDelegate.swift】

 1 import UIKit
 2
 3 @UIApplicationMain
 4 class AppDelegate: UIResponder, UIApplicationDelegate {
 5
 6     var window: UIWindow?
 7
 8     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
 9         //首先在应用程序加载完成的代理方法中,添加并配置分享平台
10         window?.makeKeyAndVisible()
11
12         //使用社会化分享的秘钥,初始化分享功能
13         ShareSDK.registerApp("1db7f78a841a4", activePlatforms:[
14             SSDKPlatformType.typeSinaWeibo.rawValue,
15             SSDKPlatformType.typeWechat.rawValue,
16             SSDKPlatformType.typeMail.rawValue,
17             SSDKPlatformType.typeSMS.rawValue,
18             SSDKPlatformType.typeQQ.rawValue],
19             //注册三个需要用到的分享平台
20              onImport: { (platform : SSDKPlatformType) in
21                 //根据各自的平台类型,连接各自的分享平台
22                 switch platform
23                 {
24                     //连接微博平台
25                     case SSDKPlatformType.typeSinaWeibo:
26                         ShareSDKConnector.connectWeibo(WeiboSDK.classForCoder())
27                     //连接微信平台
28                     case SSDKPlatformType.typeWechat:
29                         ShareSDKConnector.connectWeChat(WXApi.classForCoder())
30                     //连接QQ平台
31                     case SSDKPlatformType.typeQQ:
32                         ShareSDKConnector.connectQQ(QQApiInterface.classForCoder(), tencentOAuthClass: TencentOAuth.classForCoder())
33                     default:
34                         break
35                 }
36         //连接各分享平台后,接着对各分享平台进行配置操作
37         }) { (platform : SSDKPlatformType, appInfo : NSMutableDictionary?) in
38
39             //根据平台类型进行各自的操作
40             switch platform
41             {
42                 //根据上一篇文章的内容讲述的方法,
43                 //获得微博一样的相关秘钥信息,对微博分享平台进行配置
44                 case SSDKPlatformType.typeSinaWeibo:
45                     appInfo?.ssdkSetupSinaWeibo(byAppKey: "3112623439",
46                                                 appSecret : "4c69a099cda6104d3f9edac95ea2cc1a",
47                                                 redirectUri : "http://www.sharesdk.cn",
48                                                 authType : SSDKAuthTypeBoth)
49
50                 //对微信分享平台进行配置
51                 case SSDKPlatformType.typeWechat:
52                     appInfo?.ssdkSetupWeChat(byAppId: "wxc82577f08316d1b8", appSecret: "c6ea4756136f81c5fb8ceabebeea9fc1")
53
54                 //对QQ分享平台进行配置
55                 case SSDKPlatformType.typeQQ:
56                     appInfo?.ssdkSetupQQ(byAppId: "1106079593",
57                                          appKey : "tjawfv7ipd2inTcV",
58                                          authType : SSDKAuthTypeWeb)
59                 default:
60                     break
61             }
62         }
63         return true
64     }
65
66     func applicationWillResignActive(_ application: UIApplication) {
67         // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
68         // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
69     }
70
71     func applicationDidEnterBackground(_ application: UIApplication) {
72         // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
73         // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
74     }
75
76     func applicationWillEnterForeground(_ application: UIApplication) {
77         // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
78     }
79
80     func applicationDidBecomeActive(_ application: UIApplication) {
81         // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
82     }
83
84     func applicationWillTerminate(_ application: UIApplication) {
85         // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
86     }
87 }

在项目导航区,打开视图控制器的代码文件【ViewController.swift】

 1 import UIKit
 2
 3 class ViewController: UIViewController {
 4
 5     override func viewDidLoad() {
 6         super.viewDidLoad()
 7         // Do any additional setup after loading the view, typically from a nib.
 8
 9         //添加一个按钮对象,当用户点击按钮时,弹出分享功能面板
10         let btShare = UIButton(frame: self.view.frame)
11         //设置按钮在正常状态下的标题文字
12         btShare.setTitle("Share App", for: .normal)
13         //设置按钮在正常状态下的文字颜色
14         btShare.setTitleColor(.orange, for: .normal)
15         //为按钮绑定点击事件
16         btShare.addTarget(self, action: #selector(ViewController.share(_:)), for: .touchUpInside)
17         self.view.addSubview(btShare)
18         //将按钮添加到当前视图控制器的根视图
19     }
20
21     //添加一个方法,用来响应按钮的点击事件
22     @objc func share(_ sender: UIButton)
23     {
24         //创建一个字典对象,用来存储分享的各项信息
25         let shareParames = NSMutableDictionary()
26         //依次设置各个参数
27         shareParames.ssdkSetupShareParams(byText: "埋骨何须桑梓地,人生无处不青山!",//内容
28                                           images : UIImage(named: "share.png"),//图标
29                                           url : NSURL(string:"https://www.cnblogs.com/strengthen/")! as URL,//网址
30                                           title : "Strengthen",//标题
31                                           type : SSDKContentType.auto)//分享类型
32
33         //设置分享面板的界面为简洁风格
34         SSUIShareActionSheetStyle.setShareActionSheetStyle(.simple)
35         //最后以动作表单的方式,打开分享面板
36         ShareSDK.showShareActionSheet(nil, items: nil, shareParams: shareParames, onShareStateChanged: nil)
37     }
38
39     override func didReceiveMemoryWarning() {
40         super.didReceiveMemoryWarning()
41         // Dispose of any resources that can be recreated.
42     }
43 }

如果设备中没有安装相关的程序,点击分享后,在列表中看不到对应的分享平台。

转载于:https://www.cnblogs.com/strengthen/p/10084979.html

[Xcode 实际操作]八、网络与多线程-(25)实现ShareSdk的社会化分享功能相关推荐

  1. [Xcode 实际操作]八、网络与多线程-(17)使用网址会话对象URLSession向远程服务器上传图片...

    目录:[Swift]Xcode实际操作 本文将演示如何通过网址会话对象URLSession向远程服务器上传图片. 网址会话对象URLSession具有在后台上传和下载.暂停和恢复网络操作.丰富的代理模 ...

  2. [Xcode 实际操作]八、网络与多线程-(19)使用RunLoop使PerformSelector方法延迟动作的执行...

    目录:[Swift]Xcode实际操作 本文将演示使用RunLoop使PerformSelector方法延迟动作的执行. 在项目导航区,打开视图控制器的代码文件[ViewController.swif ...

  3. iOS开发网络篇—多线程断点下载

    iOS开发网络篇-多线程断点下载 说明:本文介绍多线程断点下载.项目中使用了苹果自带的类,实现了同时开启多条线程下载一个较大的文件.因为实现过程较为复杂,所以下面贴出完整的代码. 实现思路:下载开始, ...

  4. [Xcode 实际操作]四、常用控件-(15)MKMapView加载简单视图

    目录:[Swift]Xcode实际操作 本文将演示地图视图的使用方法. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 //首先往 ...

  5. [Xcode 实际操作]二、视图与手势-(12)UITapGestureRecognizer手势之双击

    目录:[Swift]Xcode实际操作 本文将演示使用视图的双击手势,完成视图的交互功能. 1 import UIKit 2 3 class ViewController: UIViewControl ...

  6. [Xcode 实际操作]七、文件与数据-(2)创建文件夹

    目录:[Swift]Xcode实际操作 本文将演示如何创建文件夹. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 3 class ...

  7. [Xcode 实际操作]六、媒体与动画-(3)使用CoreImage框架设置图片的单色效果

    目录:[Swift]Xcode实际操作 本文将演示如何使用图片框架,将图片转换成单色样式. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIK ...

  8. [Xcode 实际操作]六、媒体与动画-(1)使用图形上下文按一定比例缩放图片

    目录:[Swift]Xcode实际操作 本文将演示如何通过图形上下文,来实现图片缩放的功能. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UI ...

  9. [Xcode 实际操作]七、文件与数据-(3)创建文本文件、属性列表文件、图片文件

    目录:[Swift]Xcode实际操作 本文将演示如何创建各种类型的文件. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 3 c ...

最新文章

  1. LBS应用的路径引导方法
  2. 验证测试线时为什么会出现“正损耗”?
  3. python现在时间 命令_Python3 - 时间处理与定时任务
  4. c语言文件读写r 的作用,C语言 读写二进制文件
  5. python在线解题_20. 有效的括号-----leetcode刷题(python解题)
  6. from rfc 2068 hypertext怎么解决_你好,打工人!用英语怎么表达“打工人”?可别直接说 worker...
  7. linux收集完整技术支持信息的命令有,Linux下常用的日志收集命令(RedhatSuSe)
  8. 【Filebeat】windows下安装filebeat
  9. 京东面试题:ElasticSearch深度分页解决方案
  10. html外联内联,HTML内联元素
  11. 苹果承认使用谷歌云存储 iCloud 数据,但确保无隐私问题
  12. python最新技术开锁工具_Python 自动化库介绍 PySimpleGUI
  13. svn 服务器中文件删除,svn中如何彻底删除一个文件
  14. N1盒子刷入codesys当PLC使用
  15. 阅读mybatis源码
  16. 道路车辆 盲区监测(bsd)系统性能要求及试验方法_LKA、BSD国标出炉,狩猎和绞杀即将开始...
  17. 前端导入并解析excel文件,前端解析xlsx、xls格式文件、VUE解析xlsx、xls格式文件
  18. FRM 5.1 现代投资组合理论
  19. 空间轨迹分析与应用(前言)Computing with Spatial Trajectories
  20. 区块链(BTC)学习总结1

热门文章

  1. AngularJS 入门6-路由
  2. 初学JAVA 10道入门小程序
  3. PyEcharts简介
  4. 谈谈TL431与AZ431代换通用问题(个人经验)
  5. 声誉管理需要多长时间
  6. SpringBoot整合Redis客户端
  7. Initialization script ‘C:\Users\23126\AppData\Local\Temp\MyClass_main__.gradle‘ line: 21
  8. 关于matlab2016awin10 x64 版 “无法使用此产品的安装源”的解决方案
  9. 《扬帆优配》云计算板块多股涨停,龙头3月以来大涨67%
  10. Html中去除li前面的小黑点