友盟微博分享提示“网络不给力分享失败”;
这种报错一看就是版本过低了。我用的友盟库还是4.4的版本现在都到了6.0以上了。
但是微信和qq是好的。下面就是我一天的解决之道。
上午的时候在跟新pod类库;企图把友盟更新到最新版本。以下是报错和解决方案;
然后我在终端输入
$ sudo rm -fr ~/.cocoapods/repos/master
$ pod setup
$ sudo rm -fr ~/Library/Caches/CocoaPods/
OK后又报错;
好像是没有了git本地库,是自己不小心删除了。
然后在终端输入
$ cd ~/.cocoapods/repos
$ open .
打开本地cocopods的库,我手动删除;
然后在终端输入
$ git clone https://github.com/CocoaPods/Specs.git master
从新克隆一次就好了。
最后搞好了后,决定不用了。因为友盟的最新库是支持Swift3.0以上的。我还是用的Swift2.3。目前还不能更新到3.0
所以这个方案pass
下午我去微博开发者官网,下载微博的SDK,打算接入微博自己的分享。
引入微博的SDK
然后在APPdelegate里面注册,和实现他的代理方法WeiboSDKDelegate
在这个didFinishLaunchingWithOptions方法里面注册微博
//开启调试模式
WeiboSDK.enableDebugMode(true)
//设置key
WeiboSDK.registerApp(kAPPKey)
重写app delegate的方法
//微博分享设置
func application(application:UIApplication, openURL url:NSURL, sourceApplication:String?, annotation: AnyObject) -> Bool {
returnWeiboSDK.handleOpenURL(url, delegate:self)
}
func application(application:UIApplication, handleOpenURL url:NSURL) -> Bool {
returnWeiboSDK.handleOpenURL(url, delegate:self)
}
func didReceiveWeiboRequest(request:WBBaseRequest!) {
}
func didReceiveWeiboResponse(response:WBBaseResponse!) {
if response.isKindOfClass(WBSendMessageToWeiboResponse){
let sendMessageToWeiboResponse = responseas! WBSendMessageToWeiboResponse
let accessToken = sendMessageToWeiboResponse.authResponse.accessToken
if (accessToken !=nil){
self.wbtoken = accessToken
}
let userId = sendMessageToWeiboResponse.authResponse.userID
if (userId !=nil) {
self.wbCurrentUserID = userId
}
}elseif response.isKindOfClass(WBAuthorizeResponse){
// self.wbtoken = (response as! WBAuthorizeResponse).accessToken
// self.wbCurrentUserID = (response as! WBAuthorizeResponse).userID
// self.wbRefreshToken = (response as! WBAuthorizeResponse).refreshToken
}
}
//MARK: - 友盟代理-微博分享加链接
func didSelectSocialPlatform(platformName:String!, withSocialData socialData:UMSocialData!) {
// 用户点击的是微博分享则掉微博自己分享SDK
if (platformName ==UMShareToSina) {
messageShare()
}
}
//分享微博消息
func messageShare(){
let myDelegate:AppDelegate =UIApplication.sharedApplication().delegateas! AppDelegate
let authRequest:WBAuthorizeRequest =WBAuthorizeRequest.request()as! WBAuthorizeRequest
authRequest.redirectURI =kRedirectURI
authRequest.scope ="all"
let request =WBSendMessageToWeiboRequest.requestWithMessage(self.messageObject, authInfo: authRequest, access_token: myDelegate.wbtoken)as! WBSendMessageToWeiboRequest
WeiboSDK.sendRequest(request)
}
//微博消息
private var messageObject : WBMessageObject = {
let msg:WBMessageObject = WBMessageObject.message() as! WBMessageObject
msg.text = "我现正在使用友盟嵌入微博SDK,您也来试试吧。https://www.baidu.com"
return msg
}()