以微信,微博,QQ為例:分享連接:http://wiki.mob.com/快速集成指南/1: 下載ShareSDK 并導入到工程中2:在AppDelegate.h中進行相應的配置
(注釋:如果是微博的URL Schemes格式為wb+AppID? 微信的就是AppID? 已經要注意QQ的格式是QQ+AppID的16進制)
3.代碼注冊
#pragma mark=====分享
-(void)shareSDKRequest{??
[ShareSDK registerApp:@"836cd76e3f18"];//字符串api20為您的ShareSDK的AppKey? ? ?
? //添加新浪微博應用 注冊網址 http://open.weibo.com?
? [ShareSDK connectSinaWeiboWithAppKey:@"3984422795"? ? ? ? ? ? ? ? ? ? ? ? ? ? ? appSecret:@"d6d619fe4f30cc41023a747b9376e581"? ? ? ? ? ? ? ? ? ? ? ? ? ? redirectUri:@"http://www.sharesdk.cn"];? ?
//添加QQ應用? 注冊網址? 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:實現的過程(此處是自定的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];
}
具體調用的方法
-(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];? ? ??
//創建彈出菜單容器? ?
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]);? ?
? ? }? ? }];}
如果是調用的是調用系統的UI界面? ?
//創建自定義分享列表? ?
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(@"發表成功");
}else if (state == SSPublishContentStateFail){
NSLog (@"發布失敗!error code == %ld, error code == %@", (long)[error errorCode], [error errorDescription]);
}
}];