一 注册友盟账号
登录友盟官网,添加新的应用,获取Appkey
相关链接
二 申请第三方账号
三 sdk集成 CocoaPods
$ cd/你的项目地址
$ open -e Podfile
target '你的app' do
# U-Share SDK UI模块(分享面板,建议添加)
pod ‘UMengUShare/UI’
# 集成微信(精简版0.2M)
pod ‘UMengUShare/Social/ReducedWeChat'
# 集成微信(完整版14.4M)
pod ‘UMengUShare/Social/WeChat'
# 集成QQ(精简版0.5M)
pod ‘UMengUShare/Social/ReducedQQ'
# 集成QQ(完整版7.6M)
pod ‘UMengUShare/Social/QQ'
# 集成新浪微博(精简版1M)
pod ‘UMengUShare/Social/ReducedSina'
# 集成新浪微博(完整版25.3M)
pod ‘UMengUShare/Social/Sina'
end
$ pod install
四 配置文件
1.配置HTTP网络连接
在info.plist中加入安全域名白名单(右键info.plist用source code打开)
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2.配置可跳转的白名单
<key>LSApplicationQueriesSchemes</key>
<array>
<string>sinaweibo</string>
<string>sinaweibohd</string>
<string>weibosdk2.5</string>
<string>weibosdk</string>
<string>sinaweibosso</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqzone</string>
<string>sinaweibo</string>
<string>alipayauth</string>
<string>alipay</string>
<string>safepay</string>
<string>mqq</string>
<string>mqqapi</string>
<string>mqqopensdkapiV3</string>
<string>mqqopensdkapiV2</string>
<string>mqqapiwallet</string>
<string>mqqwpa</string>
<string>mqqbrowser</string>
<string>wtloginmqq2</string>
<string>weixin</string>
<string>wechat</string>
</array>
3.配置url scheme 用于跳出应用之后可以返回
targets -> Info -> URL Types
平台 | 格式 | 举例 | 备注 |
---|---|---|---|
微信 | 微信appKey | wxdc1e388c3822c80b | |
QQ/Qzone | 需要添加两项URL Scheme:1、"tencent"+腾讯QQ互联应用appID2、“QQ”+腾讯QQ互联应用appID转换成十六进制(不足8位前面补0) | 如appID:100424468 1、tencent100424468 2、QQ05fc5b14 | QQ05fc5b14为100424468转十六进制而来,因不足8位向前补0,然后加"QQ"前缀 |
新浪微博 | “wb”+新浪appKey | wb3921700954 |
4.为app瘦身(苹果官方会处理资源包,用户下载资源包变小)
targets -> Build Settings -> Enable Bitcode -> No
五 代码示例
//可直接使用
class func shareUrl(title: String, desc: String, image: UIImage, url: String, completion: ((_ succeeded: Bool) -> Void)? = nil) {
//显示分享面板
UMSocialUIManager.showShareMenuViewInWindow { (platformType, userInfo) in
//创建分享消息对象
let messageObject = UMSocialMessageObject()
//分享消息对象设置分享内容对象
let shareObject = UMShareWebpageObject.shareObject(withTitle: title, descr: desc, thumImage: image)!
//设置网页地址
shareObject.webpageUrl = url
messageObject.shareObject = shareObject
//调用分享接口
UMSocialManager.default().share(to: platformType, messageObject: messageObject, currentViewController: nil, completion: { (data, error) in
if error != nil {
print(error!.localizedDescription)
}
completion?(error == nil)
})
}
}
如有不妥,请多多指教