1.分享
1.导入sdk
2.配置
sdk(友盟的和第三方平台)放进去。添加一系列的框架。注意:要加imageIO框架。把flags 设置为-Objc,否则在注册微博时crash啊crash
3.注册
//注册友盟和微信等
[UMSocialData setAppKey:@"5603d3c967e58e5f4c001593"];
//没客户端隐藏
[UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToWechatSession, UMShareToWechatTimeline]];
4.点击分享(友盟的view)
//举例分享到微信,qq
//分享成功提示文字在窗口的上方,可以修改
[UMSocialConfig setFinishToastIsHidden:NO position:UMSocialiToastPositionCenter];
//title 正标题
[UMSocialData defaultData].extConfig.wechatTimelineData.title = SHARE_TITLE;
[UMSocialData defaultData].extConfig.wechatSessionData.title = SHARE_TITLE;
[UMSocialData defaultData].extConfig.qqData.title = SHARE_TITLE;
[UMSocialData defaultData].extConfig.qzoneData.title = SHARE_TITLE;
//微信/朋友圈 QQ url 分享后点击图片或者文字链接到网页地址 新浪不用设置
[UMSocialData defaultData].extConfig.wechatSessionData.url = STRAWBERRY_URL;
[UMSocialData defaultData].extConfig.wechatTimelineData.url = STRAWBERRY_URL;
[UMSocialData defaultData].extConfig.qqData.url = STRAWBERRY_URL;
[UMSocialData defaultData].extConfig.qzoneData.url = STRAWBERRY_URL;
NSString *shareText=[NSString stringWithFormat:@"品名:草莓(约800g)产地:上海 规格:800g/箱 包装: 保质期:2天 存储条件:冷藏"];//副标题
NSArray *arr=@[UMShareToQQ,UMShareToWechatTimeline,UMShareToWechatSession,UMShareToSina,UMShareToTencent,UMShareToSms,UMShareToRenren];
[UMSocialSnsService presentSnsIconSheetView:self appKey:nil shareText:shareText shareImage:[UIImage imageWithData:data] shareToSnsNames:arr delegate:nil];
//通常分享的图片是网络的,而要传入的是image或NSData对象,所以用ImageView 的sd_set来做
UIImageView *sharImage = [[UIImageView alloc]init];
[sharImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MSMImageApi,self.model.default_pic]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//这里可以拿到Image,从而进行上面的操作。
//注意:这里不要直接用image,最好用sharImage.image,因为用Image时sharImage已经释放了。用杀人sharImage.image则block对sharImage有个抢引用,不会释放。可能你会认为会造成循环引用,其实不然,这里的block不是sharImage 的实例变量,不会造成循环引用的
}