swift分享到微信
2015-12-11 23:58
369 查看
申请微信开发平台AppId
地址:open.weixin.qq.com
下载微信终端sdk文件
包括以下文件:
将sdk文件导入到工程
4.微信开放平台新增了微信模块用户统计功能,便于开发者统计微信功能模块的用户使用和活跃情况。开发者需要在工程中链接上:SystemConfiguration.framework,libz.dylib,libsqlite3.0.dylib,libc++.dylib
Build Settings->All->Linking
Build Phases, 增加framework,CoreTelephony和SystemConfiguration
5.桥接头文件
方法同:/article/8535532.html
Objective-CBridgingHeader.h内容如下,CommonCrypto/CommonHMAC.h可以忽略,@import UIKit;包括这个分号不可少!
6.添加微信sdk目录,我的默认就添加了。
Build Settings -> All -> SearchPaths
7.在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id(如下图所示)。
8.注册AppId
9.分享简单文字
10.分享文章到朋友,朋友圈以及收藏
调试的时候必须装有微信才行!!!
github地址
地址:open.weixin.qq.com
下载微信终端sdk文件
包括以下文件:
将sdk文件导入到工程
4.微信开放平台新增了微信模块用户统计功能,便于开发者统计微信功能模块的用户使用和活跃情况。开发者需要在工程中链接上:SystemConfiguration.framework,libz.dylib,libsqlite3.0.dylib,libc++.dylib
Build Settings->All->Linking
Build Phases, 增加framework,CoreTelephony和SystemConfiguration
5.桥接头文件
方法同:/article/8535532.html
Objective-CBridgingHeader.h内容如下,CommonCrypto/CommonHMAC.h可以忽略,@import UIKit;包括这个分号不可少!
6.添加微信sdk目录,我的默认就添加了。
Build Settings -> All -> SearchPaths
7.在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你所注册的应用程序id(如下图所示)。
8.注册AppId
9.分享简单文字
10.分享文章到朋友,朋友圈以及收藏
@IBAction func onShare(sender: UIBarButtonItem) { let sheet = UIAlertController(title: "文章 ", message: "分享到微信", preferredStyle: .ActionSheet) let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: {(action) -> Void in print("cancel share") }) let shareToFriend = UIAlertAction(title: "好朋友", style: .Destructive, handler: {(action) -> Void in self.shareToWChat(WXSceneSession) }) let shareToGroupsFriends = UIAlertAction(title: "朋友圈", style: .Destructive, handler: {(action) -> Void in self.shareToWChat(WXSceneTimeline) }) let favorite = UIAlertAction(title: "收藏", style: .Default, handler: {(action) -> Void in self.shareToWChat(WXSceneFavorite) }) sheet.addAction(cancelAction) sheet.addAction(shareToFriend) sheet.addAction(shareToGroupsFriends) sheet.addAction(favorite) self.presentViewController(sheet, animated: true, completion: {() -> Void in print("present over") }) } func shareToWChat(scene: WXScene) { let page = WXWebpageObject() page.webpageUrl = content.url let msg = WXMediaMessage() msg.mediaObject = page msg.title = (scene == WXSceneTimeline ? content.title : content.userName) msg.description = content.title switch dataType { case .GoodArticle: msg.setThumbImage(Data.sharedManager.goodArticle.imagedic[content.contentImg]) case .SearchArticle: msg.setThumbImage(Data.sharedManager.searchArticle.imagedic[content.contentImg]) default: print("data type error") } let req = SendMessageToWXReq() req.message = msg req.scene = Int32(scene.rawValue) WXApi.sendReq(req) }
调试的时候必须装有微信才行!!!
github地址
相关文章推荐
- Swift:可选类型(optional)与构造函数
- The beginning iOS8 Programming with Swift 中文翻译 - 8
- swift NSURLSession 使用方法
- Swift 利用UIScrollView和两个UIImageView实现图片轮滚
- Swift 函数做参数和闭包做参数的一个细节差别
- swift ! 和 ? 的学习
- Swift语法之 ---- ?和!区别
- Swift: 深入理解Core Animation(一)
- swift po 实现动态按钮2
- [ios][swift]Swift - 常用文件目录路径获取(Home目录,文档目录,缓存目录等)
- Swift系列之闭包(Closure)
- swift 全局常量 && 全局变量的写法
- Swift - 修改导航栏“返回”按钮文字,图标
- swift pop实现动感按钮动画
- iOS开发:Swift多线程NSOperation的使用
- Swift 枚举简单使用
- swift -- 系统学习资料
- Swift 闭包的简单学习
- swift -pop的简单动画
- Swift 吐槽下Swift里一个逼死强迫症的语法:中缀语法