这里主要是将图片保存到相册,微信好友、朋友圈,qq好友(qq空间分享纯图片没有解决,只能设置分享链接)
- 图片保存到相册
UIImageWriteToSavedPhotosAlbum(_shareImage.image,self,@selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:),nil);
#pragma mark - 保存图片后的回调
- (void)imageSavedToPhotosAlbum:(UIImage*)image didFinishSavingWithError: (NSError*)error contextInfo:(id)contextInfo
{
if(!error) {
}else {
NSString *message = [error description];
}
}
-
微信、qq
在分享之前需要集成微信、qq,这里使用cocoapods
pod "WechatOpenSDK"
pod "TencentOpenApiSDK"
在AppDelegate中注册
//微信
[WXApi registerApp:@"wxf1a8bb00646468d5" enableMTA:YES];
//qq
TencentOAuth *tencentOAuth = [[TencentOAuth alloc] initWithAppId:@"1106968509" andDelegate:self];
- 分享到微信好友
WXMediaMessage *message = [WXMediaMessage message];
// 设置消息缩略图的方法
//[message setThumbImage:[UIImage imageNamed:@"launch_logo"]];
// 多媒体消息中包含的图片数据对象
WXImageObject *imageObject = [WXImageObject object];
UIImage *image = _shareImage.image;
// 图片真实数据内容
NSData *data = UIImagePNGRepresentation(image);
imageObject.imageData = data;
// 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。
message.mediaObject = imageObject;
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneSession;
[WXApi sendReq:req];
- 分享到微信朋友圈
WXMediaMessage *message = [WXMediaMessage message];
// 设置消息缩略图的方法
//[message setThumbImage:[UIImage imageNamed:@"launch_logo"]];
// 多媒体消息中包含的图片数据对象
WXImageObject *imageObject = [WXImageObject object];
UIImage *image = _shareImage.image;
// 图片真实数据内容
NSData *data = UIImagePNGRepresentation(image);
imageObject.imageData = data;
// 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。
message.mediaObject = imageObject;
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
req.message = message;
req.scene = WXSceneTimeline;
[WXApi sendReq:req];
- 分享到qq好友
UIImage *image = _shareImage.image;
// 图片真实数据内容
NSData *data = UIImageJPEGRepresentation(image,0.5);
QQApiImageObject *imgObj = [QQApiImageObject objectWithData:data
previewImageData:data
title:@"乐伴课"
description:@"乐伴课分享"];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:imgObj];
//将内容分享到qq
[QQApiInterface sendReq:req];
- 分享到qq空间
不能分享纯图片到qq空间,折中方法分享链接到qq空间
UIImage *image = _shareImage.image;
// 图片真实数据内容
NSData *data = UIImageJPEGRepresentation(image,0.5);
QQApiNewsObject *newsObj = [QQApiNewsObject objectWithURL:[NSURL URLWithString:@"https://lebanke.cn/Admin/happyClass/phoneappdownload.html"] title:@"乐伴课" description:@"乐伴课分享" previewImageData:data];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
//将内容分享到qq空间
[QQApiInterface SendReqToQZone:req];
网友评论