今天添加了一个简单需求集成社会分享.后来决定用友盟来做.之前自己写了个微信分享的.但是考虑到后期会有扩展,所以就没有再去创轮子了.
最权威的还是看官网的教程
文档中心
看完之后基本能够做了
我习惯先看官方给出的集成可能会遇到的问题
问题
先看问题能够在心里对可能遇到的问题大致有个数,如果出现了也能快速搞定
找到的一个视图集成友盟的例子
但是感觉在autolayout下不是很好用
下面贴下自己写的部分代码
// 微信分享
- (void)ShowUMengShare{
// 客户端已经安装了微信
if([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]){
NSString *sharetext = [NSString stringWithFormat:@"",product.name,product.prospectiveProfitRate];
NSString *sessionTitle = @"";
NSString *timelineTitle = @"";
// 设置图文分享
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
// 设置当分享消息类型为图文时,点击分享内容会跳转到预设的链接
[UMSocialData defaultData].extConfig.wechatSessionData.url = kHeCaiFuWeb;
// 设置微信好友title
[UMSocialData defaultData].extConfig.wechatSessionData.title = sessionTitle;
// 设置微信朋友圈title
[UMSocialData defaultData].extConfig.wechatTimelineData.title = timelineTitle;
[UMSocialSnsService presentSnsIconSheetView:self
appKey:kUMengShareAppKey
shareText:sharetext
shareImage:[UIImage imageNamed:@"product_Icon"]
shareToSnsNames:[NSArray arrayWithObjects:UMShareToWechatSession,UMShareToWechatTimeline,nil]
delegate:self];
}else{
// 未安装微信
UIAlertView *alterView = [[UIAlertView alloc]initWithTitle:@"请先安装微信"
message:nil
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles: nil];
[alterView show];
}
}
// 微信分享成功后回调方法
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
NSString *title = @”分享到微信”;
NSString *recallInfo = @”“;
//根据responseCode
得到发送结果,如果分享成功
if(response.responseCode == UMSResponseCodeSuccess)
{
// 分享成功
recallInfo = @”成功分享到微信”;
}else{
// 分享失败
recallInfo = @”让我在想会儿!!”;
}
UIAlertView *alterView = [[UIAlertView alloc]initWithTitle:title
message:recallInfo
delegate:self
cancelButtonTitle:@”取消”
otherButtonTitles:nil];
[alterView show];
}