将下载的SDK拖入工程中
然后倒入需要的系统库
libUMSocial_Sdk_4.4.a liz.1.2.5.tbd libsqlite3.0.tbd libiconv.2.4.0.tbd libstdc++.6.0.9.tbd CoreTelephony.framework CoreGraphics.framework Security.framework SystemConfiguration.framework
注:以上是需要手动导入的系统库,其中libUMSocial_Sdk_4.4.a
在UMSocial_Sdk_4.4目录中,必须导入,不然编译错误。
下面是完整的库图:
库都确认无误后,开始配置URL Schemes
微信:wxd9a39c7122aa6516
腾讯:QQ05FC5B14
腾讯:tencent100424468
新浪微博网页版无需设置URL Schemes
info.plist配置
Bundle display name
要设置APP名,否则无法分享到QQ
然后配置IOS9白名单LSApplicationQueriesSchemes
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- 微信 URL Scheme 白名单-->
<string>wechat</string>
<string>weixin</string>
<!-- 新浪微博 URL Scheme 白名单-->
<string>sinaweibohd</string>
<string>sinaweibo</string>
<string>sinaweibosso</string>
<string>weibosdk</string>
<string>weibosdk2.5</string>
<!-- QQ、Qzone URL Scheme 白名单-->
<string>mqqapi</string>
<string>mqq</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqconnect</string>
<string>mqqopensdkdataline</string>
<string>mqqopensdkgrouptribeshare</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkapi</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>mqzoneopensdk</string>
<string>wtloginmqq</string>
<string>wtloginmqq2</string>
<string>mqqwpa</string>
<string>mqzone</string>
<string>mqzonev2</string>
<string>mqzoneshare</string>
<string>wtloginqzone</string>
<string>mqzonewx</string>
<string>mqzoneopensdkapiV2</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapi</string>
<string>mqzoneopensdk</string>
<!-- 支付宝 URL Scheme 白名单-->
<string>alipay</string>
<string>alipayshare</string>
</array>
IOS9网络请求
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
以上都配置完就可以写代码了
AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// 友盟默认网页新浪微博分享
UMSocialData.setAppKey("569cb35867e58e430d000d48")
// 微信
UMSocialWechatHandler.setWXAppId("wxd930ea5d5a258f4f", appSecret:"db426a9829e4b49a0dcac7b4162da6b6", url:"http://www.umeng.com/social")
// QQ
UMSocialQQHandler.setQQWithAppId("100424468", appKey:"c7394704798a158208a74ab60104f0ba", url:"http://www.umeng.com/social")
return true
}
// QQ、微信返回当前应用时拦截获取url和参数
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
let result = UMSocialSnsService.handleOpenURL(url)
if (result == false) {
//调用其他SDK,例如支付宝SDK等
}
return result
}
}
ViewController.swift
import UIKit
class ViewController: UIViewController,UMSocialUIDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
UMSocialSnsService.presentSnsIconSheetView(self, appKey: "569cb35867e58e430d000d48", shareText: "测试、测试,http://baidu.com", shareImage: nil, shareToSnsNames: [UMShareToSina,UMShareToWechatSession,UMShareToQQ], delegate: self)
}
}
网友评论