mob中ShareSDK分享總結(jié)


以微信,微博,QQ為例:分享連接:http://wiki.mob.com/快速集成指南/1: 下載ShareSDK 并導入到工程中2:在AppDelegate.h中進行相應的配置


(注釋:如果是微博的URL Schemes格式為wb+AppID? 微信的就是AppID? 已經(jīng)要注意QQ的格式是QQ+AppID的16進制)

3.代碼注冊

#pragma mark=====分享

-(void)shareSDKRequest{??

[ShareSDK registerApp:@"836cd76e3f18"];//字符串a(chǎn)pi20為您的ShareSDK的AppKey? ? ?

? //添加新浪微博應用 注冊網(wǎng)址 http://open.weibo.com?

? [ShareSDK connectSinaWeiboWithAppKey:@"3984422795"? ? ? ? ? ? ? ? ? ? ? ? ? ? ? appSecret:@"d6d619fe4f30cc41023a747b9376e581"? ? ? ? ? ? ? ? ? ? ? ? ? ? redirectUri:@"http://www.sharesdk.cn"];? ?

//添加QQ應用? 注冊網(wǎng)址? http://mobile.qq.com/api/? 六十進制為 41D5A2C9?

? [ShareSDK connectQQWithQZoneAppKey:@"1104519881"??? ? qqApiInterfaceCls:[QQApiInterface class]? ? ? ? ? ? ? ? ? ? ? tencentOAuthCls:[TencentOAuth class]];?

? //添加微信應用? http://open.weixin.qq.com? ?

[ShareSDK connectWeChatWithAppId:@"wxf5f94e45ff12229b"? ? ? ? ? ? ? ? ? ? ? ? ? appSecret:@"21dea7739efd236a5f6f7ea34b6a1c84"?? ? wechatCls:[WXApi class]];

}

4:實現(xiàn)的過程(此處是自定的UI分享界面)效果圖如下:


-(void)shareEvent:(UIButton*)sender{? ? ??

if(sender.tag==100){? ? ??

[self shareSDKDemo:ShareTypeWeixiSession];??

}else if (sender.tag==101){? ? ??

//QQ? ? ? ? [self shareSDKDemo: ShareTypeQQ];? ?

}else{? ? ? ?

//weibo? ? ? ? [self shareSDKDemo:ShareTypeSinaWeibo];??

}??

[_shareBgView removeFromSuperview];?

? [_shareView removeFromSuperview];

}

具體調(diào)用的方法

-(void)shareSDKDemo:(ShareType)type {? ?

//新聞的連接拼接

? [NSString stringWithFormat:@"http://120.26.111.132:8090/wh/pages/mobile/article.jsp?aid=%d",2]

? if (self.newsTypeSign==50) {? ? ? ?

self.newsPath=[NSString stringWithFormat:@"http://120.26.111.132:8090/wh/pages/mobile/article.jsp?bid=%ld",(long)self.bannerId];? ?

}else{? ? ??

self.newsPath=[NSString stringWithFormat:@"http://120.26.111.132:8090/wh/pages/mobile/article.jsp?aid=%ld",(long)self.arctiveId];? ?

}? ?

id<ISSContent>publishContent = [ShareSDK content:self.titleName? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? defaultContent:@"haha"? ??? image:[ShareSDK imageWithUrl:self.thumbpath]? ?? title:self.titleName? ??? url:self.newsPath? ?? description:@"zhong"? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mediaType:SSPublishContentMediaTypeNews];? ? ??

//創(chuàng)建彈出菜單容器? ?

id<ISSContainer>container = [ShareSDK container];? ? [container setIPadContainerWithView:self.view arrowDirect:UIPopoverArrowDirectionUp];?

? //分享 客戶端分享?

? [ShareSDK showShareViewWithType:type container:container content:publishContent statusBarTips:YES authOptions:nil shareOptions:nil result:^(ShareType type, SSResponseState state, idstatusInfo, iderror, BOOL end) {? ? ??

if (state == SSPublishContentStateSuccess)? ? ? ? {? ? ? ??

? [self showStringHUD:@"分享成功" second:1];? ? ?

? }? ? else if (state == SSPublishContentStateFail)? ? ? ? {? ? ? ? ?

? NSLog(@"分享失敗,錯誤碼:%ld,錯誤描述:%@", (long)[error errorCode], [error errorDescription]);? ?

? ? }? ? }];}

如果是調(diào)用的是調(diào)用系統(tǒng)的UI界面? ?

//創(chuàng)建自定義分享列表? ?

NSArray *shareList = [ShareSDK customShareListWithType: sinaItem,? ? tencentItem,? ? ? ? ? ? ? ? ? ? ? ? ? [NSNumber numberWithInteger:ShareTypeWeixiSession],??? [NSNumber numberWithInteger:ShareTypeWeixiTimeline],?? [NSNumber numberWithInteger:ShareTypeQQ],? ? ? ? ? ? ? ? ? ? ? ? ? [NSNumber numberWithInteger:ShareTypeQQSpace],? ?? nil];?

? //分享接口? ?

[ShareSDK showShareActionSheet:container? ? shareList:shareList? ??? content:publishContent? ? ? ? ? ? ? ? ? ? statusBarTips:YES??? ? authOptions:nil? ?? shareOptions:nil?? result:^(ShareType type, SSResponseState state, idstatusInfo, iderror, BOOL end) {

if (state == SSPublishContentStateSuccess){

NSLog(@"發(fā)表成功");

}else if (state == SSPublishContentStateFail){

NSLog (@"發(fā)布失敗!error code == %ld, error code == %@", (long)[error errorCode], [error errorDescription]);

}

}];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容