//
//  ShareViewController.m
//  Lighting
//
//  Created by mac on 16/5/23.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ShareViewController.h"

@interface ShareViewController ()

@end

@implementation ShareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initSubview];
   
}
-(void)initSubview
{
    self.weiXinFriend=[[UIButton alloc]initWithFrame:CGRectMake(25, 25,60 , 60)];
    [self.weiXinFriend setBackgroundImage:[UIImage imageNamed:@"wechat"] forState:UIControlStateNormal];
    self.weiXinFriend.tag=101;
    [self.weiXinFriend addTarget:self action:@selector(sharePicture:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.weiXinFriend];
    UILabel *lable1=[[UILabel alloc]initWithFrame:CGRectMake(25, 90, 60, 40)];
    lable1.text=@"微信好友";
    lable1.font=[UIFont systemFontOfSize:12];
    [self.view addSubview:lable1];
    
    self.weiXinFriendCircle=[[UIButton alloc]initWithFrame:CGRectMake(25+25+60, 25,60 , 60)];
    [self.weiXinFriendCircle setBackgroundImage:[UIImage imageNamed:@"Friends-Circle"] forState:UIControlStateNormal];
    self.weiXinFriendCircle.tag=102;
    [self.weiXinFriendCircle addTarget:self action:@selector(sharePicture:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.weiXinFriendCircle];
    UILabel *lable2=[[UILabel alloc]initWithFrame:CGRectMake(25+25+60, 90, 60, 40)];
    lable2.text=@"微信朋友圈";
    lable2.font=[UIFont systemFontOfSize:12];
    [self.view addSubview:lable2];
    
    self.sinaMicroBlog=[[UIButton alloc]initWithFrame:CGRectMake(25+25+60+25+60, 25,60 , 60)];
    [self.sinaMicroBlog setBackgroundImage:[UIImage imageNamed:@"weibo"] forState:UIControlStateNormal];
    self.sinaMicroBlog.tag=103;
    [self.sinaMicroBlog addTarget:self action:@selector(sharePicture:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.sinaMicroBlog];
    UILabel *lable3=[[UILabel alloc]initWithFrame:CGRectMake(25+25+60+25+60, 90, 60, 40)];
    lable3.text=@"新浪微博";
    lable3.font=[UIFont systemFontOfSize:12];
    [self.view addSubview:lable3];

}
-(void)sharePicture:(UIButton*)sender
{
    if ([self.delegate respondsToSelector:@selector(addProductImage:productModel:)]) {
        
        [self.delegate ShareProductImage:nil];
    }

    switch (sender.tag) {
        case 101:
        {//默认分享样式
            [UMSocialData defaultData].extConfig.wechatSessionData.title = @"标题";// 微信title
            [UMSocialData defaultData].extConfig.wechatTimelineData.title = @"标题";// 微信朋友圈title
            [UMSocialData defaultData].extConfig.qqData.title = @"标题";// QQ分享title
            [UMSocialData defaultData].extConfig.qzoneData.title = @"标题";// Qzone分享title
            //注意： 1. 支持分享编辑页和授权页面横屏，必须要在出现列表页面前设置:
            [UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape];
            // 显示分享界面
            [UMSocialSnsService presentSnsIconSheetView:self appKey:@"57425f2467e58e645f00210a"  shareText:@"友盟社会化分享让您快速实现分享等社会化功能，http://umeng.com/social"
                                             shareImage:[UIImage imageNamed:@"icon"] shareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ,UMShareToQzone]
                                               delegate:self];
        }
            
            break;
        case 102:
        {
            [UMSocialData defaultData].extConfig.title = @"分享的title";
            [UMSocialData defaultData].extConfig.qqData.url = @"http://baidu.com";
            [UMSocialSnsService presentSnsIconSheetView:self
                                                 appKey:@"57425f2467e58e645f00210a"
                                              shareText:@"友盟社会化分享让您快速实现分享等社会化功能，http://umeng.com/social"
                                             shareImage:[UIImage imageNamed:@"icon"]
                                        shareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ,UMShareToQzone]
                                               delegate:self];
        }
            break;
        case 103:
        {
//            自定义分享样式
            //需要自定义面板样式的开发者需要自己绘制UI，在对应的分享按钮中调用此接口
            //使用UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToSina] content:@"分享内嵌文字" image:nil location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    NSLog(@"分享成功！");
                }
            }];
        }
            
            break;
            
        default:
            break;
    }
    
}
//实现回调方法：
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
