Swift-友盟分享

Swift-友盟分享_第1张图片

将下载的SDK拖入工程中

Swift-友盟分享_第2张图片

然后倒入需要的系统库
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目录中,必须导入,不然编译错误。

下面是完整的库图:


Swift-友盟分享_第3张图片

库都确认无误后,开始配置URL Schemes

微信:wxd9a39c7122aa6516
腾讯:QQ05FC5B14
腾讯:tencent100424468

新浪微博网页版无需设置URL Schemes


Swift-友盟分享_第4张图片

info.plist配置

Bundle display name要设置APP名,否则无法分享到QQ
然后配置IOS9白名单LSApplicationQueriesSchemes

LSApplicationQueriesSchemes
 
    
    wechat
    weixin

    
    sinaweibohd
    sinaweibo
    sinaweibosso
    weibosdk
    weibosdk2.5

    
    mqqapi
    mqq
    mqqOpensdkSSoLogin
    mqqconnect
    mqqopensdkdataline
    mqqopensdkgrouptribeshare
    mqqopensdkfriend
    mqqopensdkapi
    mqqopensdkapiV2
    mqqopensdkapiV3
    mqzoneopensdk
    wtloginmqq
    wtloginmqq2
    mqqwpa
    mqzone
    mqzonev2
    mqzoneshare
    wtloginqzone
    mqzonewx
    mqzoneopensdkapiV2
    mqzoneopensdkapi19
    mqzoneopensdkapi
    mqzoneopensdk

    
    alipay
    alipayshare


IOS9网络请求

NSAppTransportSecurity

    NSAllowsArbitraryLoads
    


以上都配置完就可以写代码了

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, withEvent event: UIEvent?) {
        UMSocialSnsService.presentSnsIconSheetView(self, appKey: "569cb35867e58e430d000d48", shareText: "测试、测试,http://baidu.com", shareImage: nil, shareToSnsNames: [UMShareToSina,UMShareToWechatSession,UMShareToQQ], delegate: self)
    }
}

你可能感兴趣的:(Swift-友盟分享)