现在分享大部分用的是shareSDK和友盟分享,官方建议的是图文+文字分享,下面介绍一下单纯分享图片可以放大的方法
友盟分享
- (void)shareAction
{
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:ctx];
// 这个是要分享图片的样式(自定义的)
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// 微信分享 纯图片
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeImage;
// QQ分享消息类型分为图文、纯图片,QQ空间分享只支持图文分享(图片文字缺一不可)
[UMSocialData defaultData].extConfig.qqData.qqMessageType = UMSocialQQMessageTypeImage;
[UMSocialSnsService presentSnsIconSheetView:self
appKey:UMENG_APP_KEY
shareText:nil
shareImage:newImage
shareToSnsNames:@[UMShareToQQ, UMShareToWechatSession, UMShareToWechatTimeline,UMShareToWechatFavorite, UMShareToSina]
delegate:self];
}
//下面得到分享完成的回调
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
// NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response);
//根据`responseCode`得到发送结果,如果分享成功
if(response.responseCode == UMSResponseCodeSuccess)
{
//得到分享到的微博平台名
// NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
}
}
-(void)didFinishShareInShakeView:(UMSocialResponseEntity *)response
{
// NSLog(@"finish share with response is %@",response);
}
shareSDK
// 在下面的block中用到,采取弱引用(ShareImageViewController是我自己分享页面的控制器)
__weak ShareImageViewController *theController = self;
//1、创建分享参数(必要)
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKEnableUseClientShare];
// 分享的图片可以是本地可以使网络图片(自己做处理)
NSArray* imageArray = @[newImage];
// 自定义分享文字内容
NSString *realName = self.data_Dict[@"realname"];
NSString *bodyText = [NSString stringWithFormat:@"%@邀请好友加入杉山盆底,即刻开始多点执业", realName];
[shareParams SSDKSetupShareParamsByText:bodyText
images:imageArray
url:nil
title:@"我的分享"
type:SSDKContentTypeAuto];
[ShareSDK showShareActionSheet:self.view
items:@[@(SSDKPlatformSubTypeWechatSession), @(SSDKPlatformSubTypeWechatTimeline), @(SSDKPlatformSubTypeQQFriend),@(SSDKPlatformTypeSinaWeibo), @(SSDKPlatformSubTypeWechatFav)]
shareParams:shareParams
onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
manager.enable = YES;
[manager resignFirstResponder];
switch (state) {
case SSDKResponseStateBegin:
{
[theController showLoadingView:YES];
break;
}
case SSDKResponseStateSuccess:
{
if (platformType == SSDKPlatformTypeFacebookMessenger)
{
break;
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alertView show];
[self.view resignFirstResponder];
break;
}
case SSDKResponseStateFail:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败" message:[NSString stringWithFormat:@"%@",error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
break;
}
case SSDKResponseStateCancel:
{
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
// [alertView show];
// break;
}
default:
break;
}
if (state != SSDKResponseStateBegin)
{
[theController showLoadingView:NO];
}
}];
}
/**
* 显示加载动画
*
* @param flag YES 显示,NO 不显示
*/
- (void)showLoadingView:(BOOL)flag
{
if (flag)
{
[self.view addSubview:self.panelView];
[self.loadingView startAnimating];
}
else
{
[self.panelView removeFromSuperview];
}
}