本文主要是介绍集成ShareSDK分享当前屏幕图片的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
-(void)btnShare
{
// download URL
NSString *strURL = [NSString stringWithFormat:@"http://dev.kumoway.com/healthrun"];
DatabaseManager *dm = [[DatabaseManager alloc] init];
VHSActionData *actionlData = [dm selectOneFromActionLst:_actionId];
// 微博文字内容140字
NSString *strWeibo = [NSString stringWithFormat:@"我在%@,使用“Runner”运动了%0.2f公里,用时%@。\n\nhttp://dev.kumoway.com/healthrun\n",actionlData.startTime,actionlData.distance,[VHSCommon getHmsFromSecond:actionlData.seconds]];
UIImage *shareimage = [self imageFromView:self.view];
// 分享内容协议
id<ISSContent> publishContent = [ShareSDK content:strWeibo
defaultContent:strWeibo
image:[ShareSDK pngImageWithImage:shareimage]
title:@"Runner"
url:strURL
description:nil
mediaType:SSPublishContentMediaTypeImage];
// 定制邮件
[publishContent addMailUnitWithSubject:@"Runner"
content:strWeibo
isHTML:[NSNumber numberWithBool:NO]
attachments:INHERIT_VALUE
to:INHERIT_VALUE
cc:INHERIT_VALUE
bcc:INHERIT_VALUE];
//定制新浪微博
[publishContent addSinaWeiboUnitWithContent:INHERIT_VALUE
image:INHERIT_VALUE];
//定制微信好友信息
[publishContent addWeixinSessionUnitWithType:INHERIT_VALUE
content:INHERIT_VALUE
title:@"Runner"
url:INHERIT_VALUE
thumbImage:INHERIT_VALUE
image:INHERIT_VALUE
musicFileUrl:nil
extInfo:nil
fileData:nil
emoticonData:nil];
// 定制QQ
[publishContent addQQUnitWithType:[NSNumber numberWithInt:SSPublishContentMediaTypeImage]
content:INHERIT_VALUE
title:INHERIT_VALUE
url:strURL
image:INHERIT_VALUE];
//定制人人网信息
[publishContent addRenRenUnitWithName:@"Runner"
description:strWeibo
url:INHERIT_VALUE
message:strWeibo
image:[ShareSDK pngImageWithImage:shareimage]
caption:INHERIT_VALUE];
//创建弹出菜单容器
id<ISSContainer> container = [ShareSDK container];
[container setIPadContainerWithView:self.view arrowDirect:UIPopoverArrowDirectionAny];
//设置导航栏的view delegate
viewDelegate = [[AGViewDelegate alloc] init];
id<ISSAuthOptions> authOptions = [ShareSDK authOptionsWithAutoAuth:YES
allowCallback:YES
authViewStyle:SSAuthViewStyleFullScreenPopup
viewDelegate:viewDelegate
authManagerViewDelegate:viewDelegate];
//在授权页面中添加关注官方微博
[authOptions setFollowAccounts:[NSDictionary dictionaryWithObjectsAndKeys:
[ShareSDK userFieldWithType:SSUserFieldTypeName value:@"ShareSDK"],
SHARE_TYPE_NUMBER(ShareTypeSinaWeibo),
[ShareSDK userFieldWithType:SSUserFieldTypeName value:@"ShareSDK"],
SHARE_TYPE_NUMBER(ShareTypeTencentWeibo),
nil]];
id<ISSShareOptions> shareOptions = [ShareSDK defaultShareOptionsWithTitle:@"Runner"
oneKeyShareList:[NSArray defaultOneKeyShareList]
qqButtonHidden:YES
wxSessionButtonHidden:YES
wxTimelineButtonHidden:YES
showKeyboardOnAppear:NO
shareViewDelegate:viewDelegate
friendsViewDelegate:viewDelegate
picViewerViewDelegate:nil];
// 定制分享列表
NSArray *shareList = [ShareSDK getShareListWithType:
ShareTypeWeixiSession,
ShareTypeWeixiTimeline,
ShareTypeQQ,
ShareTypeSinaWeibo,
ShareTypeRenren,
ShareTypeDouBan,
nil];
//弹出分享菜单
[ShareSDK showShareActionSheet:container
shareList:shareList
content:publishContent
statusBarTips:YES
authOptions:authOptions
shareOptions:shareOptions
result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
bgView.hidden = YES;
if (state == SSResponseStateSuccess)
{
[PXAlertView showAlertWithTitle:@"提示" message:@"分享成功" cancelTitle:LABEL_BUTTON_CONFIRM completion:^(BOOL cancelled) {
}];
}
else if (state == SSResponseStateFail)
{
[PXAlertView showAlertWithTitle:@"提示" message:@"分享失败" cancelTitle:LABEL_BUTTON_CONFIRM completion:^(BOOL cancelled) {
}];
}
}];
}
// iphone 截屏方法
- (UIImage *)imageFromView:(UIView *)theView
{
UIGraphicsBeginImageContext(theView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[theView.layer renderInContext: context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
这篇关于集成ShareSDK分享当前屏幕图片的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!