ShareGoodsViewController.m 6.66 KB
Newer Older
勾芒's avatar
勾芒 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
//
//  ShareGoodsViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/6/3.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ShareGoodsViewController.h"

@interface ShareGoodsViewController ()

@end

@implementation ShareGoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

21 22 23 24
#pragma mark - 压缩图片
- (void)setShareImage:(UIImage *)shareImage
{
    _shareImage = [UIImage imageWithData:UIImageJPEGRepresentation(shareImage, 0.2)];
勾芒's avatar
勾芒 committed
25
}
26

勾芒's avatar
勾芒 committed
27 28 29
#pragma mark -分享
- (IBAction)ShareWeiChatAntWeiboAction:(UIButton *)sender {
    
30
    WS(weakSelf);
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    switch (self.type) {
            case SHARE_GOODS:
        {
            NSData *imageData = UIImageJPEGRepresentation(self.shareImage, 0.5);
            NSString *goodsID = [self.shareID substringToIndex:[self.shareID length]-1];
            NSDictionary *parameterDict = [NSDictionary dictionaryWithObjectsAndKeys:[goodsID substringToIndex:self.shareID.length-1],@"goodsIds",@"",@"title",@"",@"remark",nil];
            XBLoadingView *progressView = [XBLoadingView showHUDViewProgressLabel:@"上传图片中"];
            [HTTP uploadImageWithURL:SERVERREQUESTURL(SHARE) withRequestType:ZERO withImageDatas:imageData withParameter:parameterDict withReturnValueBlock:^(id returnValue) {
                
                if (RESULT(returnValue)) {
                    NSString *shareWeb = returnValue[@"data"][@"url"];
                    [self callSharePlatform:shareWeb withPlatformTag:sender withTitle:ShareTitle];
                }else
                {
                    [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
                }
            }withprogressBlock:^(double progress) {
                if (progress >= 1) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        progressView.labelText = @"上传成功";
                        [progressView hide:YES];
                    });
                    
                }else{
                    progressView.progress = progress;
                }
                
            } withFailureBlock:^(NSError *error) {
                [XBLoadingView hideHUDViewWithDefault];
                [XBLoadingView showHUDViewWithText:error.localizedDescription];
            }];
        }
            break;
            case SHARE_ORDER:
        {
            [XBLoadingView showHUDViewWithDefault];
            NSString *shareOrderString = [NSString stringWithFormat:@"%@/%@",SHAREORDERBILL,self.shareID];
            [HTTP networkWithDictionaryRequestWithURL:SERVERREQUESTURL(shareOrderString) withRequestType:ZERO withParameter:nil withReturnValueBlock:^(id returnValue) {
                
                [XBLoadingView hideHUDViewWithDefault];
                if (RESULT(returnValue)) {
                    [weakSelf callSharePlatform:returnValue[@"data"][@"url"] withPlatformTag:sender withTitle:@"欧立方订单一键分享"];
                }else
                {
                    [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
                }
                
            } withFailureBlock:^(NSError *error) {
                [XBLoadingView hideHUDViewWithDefault];
                [XBLoadingView showHUDViewWithText:error.localizedDescription];
            }];
        }
            break;
            case SHARE_INVITATION:
        {
            [XBLoadingView showHUDViewWithDefault];
            NSString *string = [NSString stringWithFormat:SHAREINVITATION,self.shareID];
            [HTTP networkWithDictionaryRequestWithURL:SERVERREQUESTURL(string) withRequestType:ZERO withParameter:nil withReturnValueBlock:^(id returnValue) {
                
                [XBLoadingView hideHUDViewWithDefault];
                if (RESULT(returnValue)) {
                    [weakSelf callSharePlatform:returnValue[@"data"][@"url"] withPlatformTag:sender withTitle:@"欧立方论坛一键分享"];
                }else
                {
                    [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
                }
                
            } withFailureBlock:^(NSError *error) {
                [XBLoadingView hideHUDViewWithDefault];
                [XBLoadingView showHUDViewWithText:error.localizedDescription];
            }];
        }
            break;
        default:
            break;
106 107
    }
}
曹云霄's avatar
曹云霄 committed
108

109
#pragma mark - 调用分享
曹云霄's avatar
曹云霄 committed
110
- (void)callSharePlatform:(NSString *)shareWeb withPlatformTag:(UIButton *)sender withTitle:(NSString *)title
111 112 113 114 115 116
{
    switch (sender.tag) {
        case 100: //微信好友
        {//自定义样式
            //使用UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
            [UMSocialData defaultData].extConfig.wechatSessionData.url = shareWeb;
曹云霄's avatar
曹云霄 committed
117
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:title image:self.shareImage location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
118
                if (response.responseCode == UMSResponseCodeSuccess) {
119
                    [XBLoadingView showHUDViewWithSuccessText:@"分享微信好友成功" completeBlock:nil];
120 121 122 123 124
                }
            }];
        }
            break;
        case 101://微信朋友圈
勾芒's avatar
勾芒 committed
125
        {
126 127
            //使用UMShareToWechatSession,UMShareToWechatTimeline,UMShareToWechatFavorite分别代表微信好友、微信朋友圈、微信收藏
            [UMSocialData defaultData].extConfig.wechatTimelineData.url = shareWeb;
曹云霄's avatar
曹云霄 committed
128
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:title image:self.shareImage location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
129
                if (response.responseCode == UMSResponseCodeSuccess) {
130
                    [XBLoadingView showHUDViewWithSuccessText:@"分享微信朋友圈成功" completeBlock:nil];
131 132
                }
            }];
勾芒's avatar
勾芒 committed
133
        }
134 135 136 137 138
            break;
        case 102://新浪微博
        {
            //自定义分享样式
            [UMSocialData defaultData].extConfig.sinaData.shareText = [NSString stringWithFormat:@"%@%@",@"欧普照明",shareWeb];
曹云霄's avatar
曹云霄 committed
139
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToSina] content:title image:self.shareImage location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *shareResponse){
140
                if (shareResponse.responseCode == UMSResponseCodeSuccess) {
141
                    [XBLoadingView showHUDViewWithSuccessText:@"分享新浪微博成功" completeBlock:nil];
142 143
                }
            }];
勾芒's avatar
勾芒 committed
144
        }
145 146 147 148
            break;
        default:
            break;
    }
勾芒's avatar
勾芒 committed
149 150 151 152
}


@end