1. 把 UMSocial_Sdk_4.XX导入 (用上手机QQ,微信,手机微博要另外导入UMSocial_Sdk_Extra_Frameworks)
2.在工程的 build Phases 的 Link Binary With Libraries 导入
系统库SystemConfiguration.framework2. 若你的工程设置了all_load,需要添加手机QQ SDK需要的系统framework:Security.framework,libiconv.dylib,CoreGraphics.framework,libsqlite3.dylib,CoreTelephony.framework,libstdc++.dylib,libz.dylib。(假如导入 UMSocial_Sdk_Extra_Frameworks 文件夹后 更要导入里面的.a文件 如 libSocialSina.a)
3.必须真机测试 不然报错 (而且别搞错版本 比如 UMSocial_Sdk_4.2的 那么UMSocial_Sdk_Extra_Frameworks 也要用到4.2的)
代码
4. 在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 里面写
[UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatSession,UMShareToWechatTimeline]];//隐藏没安装的客户端
[UMSocialData setAppKey:@"52aec32756240bc4c4XXXXX"];
//设置微信AppId、appSecret,分享url
[UMSocialWechatHandler setWXAppId:@"wx8cf7ec5XXXXXXa" appSecret:@"c7eac15b096adXXXXX0d6f2fc" url:Application_url];
//设置手机QQ 的AppId,Appkey,和分享URL,需要#import "UMSocialQQHandler.h"
[UMSocialQQHandler setQQWithAppId:@"10XXXX761" appKey:@"937c25XXXX4a0acfd9" url:Application_url];
//打开新浪微博的SSO开关,设置新浪微博回调地址,这里必须要和你在新浪微博后台设置的回调地址一致。若在新浪后台设置我们的回调地址,“http://sns.whalecloud.com/sina2/callback”,这里可以传nil ,需要 #import "UMSocialSinaHandler.h"
[UMSocialSinaHandler openSSOWithRedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
注意 :新浪分享的时候
[UMSocialSinaHandler openSSOWithRedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
必须和 新浪开放平台的回调页一致 否则 sso授权认证 的时候 登陆失败
然后在appdelegate.m其他地方写上
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [UMSocialSnsService handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [UMSocialSnsService handleOpenURL:url];
}
以上方法新浪分享需要用到的
5.记得去info。plist 设置 url types
之后就是 点击分享的代码了
#pragma mark --cell点击更多
- (void)moreButtonClicked:(UIButton *)sender {
NSLog(@"sender.tag = %ld",(long)sender.tag);
ContentResponseEntity * model = [discoveryDataArray objectAtIndex:sender.tag];
[UMSocialSnsService presentSnsIconSheetView:self
appKey:@"52aec32756240XXXXX2"
shareText:model.info.content
shareImage:[UIImage imageNamed:@"Default"]
shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToWechatSession, UMShareToWechatTimeline, UMShareToQzone, UMShareToQQ, UMShareToEmail, UMShareToSms,nil]
delegate:self];
}
//弹出列表方法presentSnsIconSheetView需要设置delegate为self
-(BOOL)isDirectShareInIconActionSheet
{
return YES;
}
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
//根据`responseCode`得到发送结果,如果分享成功
if(response.responseCode == UMSResponseCodeSuccess)
{
//得到分享到的微博平台名
NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
}
}
单独分享有2个方式 一种是
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:@"友盟社会化分享让您快速实现分享等社会化功能,http://umeng.com/social" image:nil location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
NSLog(@"分享成功!");
}
}];
这种不会跳到编辑页面 只能直接分享设置好的内容
下面还有一种是跳到编辑页面 有2个代码 上一句是设置分享内容和图片 下一句是跳到哪个的编辑页面
[[UMSocialControllerService defaultControllerService] setShareText:@"友盟社会化分享让您快速实现分享等社会化功能,http://umeng.com/social" shareImage:nil socialUIDelegate:self]; //设置分享内容和回调对象
[UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
分享视频连接的时候
[[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeVideo url:self.model.info.url];
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:[NSString stringWithFormat:@"%@ @赞逗鸡",self.model.info.content] image:nil location:nil urlResource:[UMSocialData defaultData].urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
NSLog(@"分享成功!");
[self initShareBgView];
}
}];
要是用了urlResource的话 分享出来的后面就会加个网页连接 假如是视频 会有个小图片的视频连接
接假如是GIF图的话 就不要用这个网页连接了 直接转成data 放到image里面
NSData *gifData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[self.model.info.imgPath objectAtIndex:0]] ];
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:[NSString stringWithFormat:@"%@ @赞逗鸡",self.model.info.content] image:gifData location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
NSLog(@"分享成功!");
[self initShareBgView];
}
}];
注意:单独的分享的话要 另外用别的api 去检测 QQ和微信是否已经安装
假如没有安装 就不能出现这个分享,不然苹果审核不过关。
[QQApiInterface isQQInstalled];
[WXApi isWXAppInstalled];
以上2个是检测api. 记得导入
#import "WXApi.h"
#import "UMSocialQQHandler.h"
2个类
// //查询账号
[[UMSocialDataService defaultDataService] requestSocialAccountWithCompletion:^(UMSocialResponseEntity *response) {
NSLog(@"response = %@",[[[response.data objectForKey:@"accounts"] objectForKey:@"sina"] objectForKey:@"usid"]);
// sinaShareUserId
}];
//解除绑定
[[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina completion:^(UMSocialResponseEntity *response){
NSLog(@"response is %@",response);
}];