ShareGoodsViewController.m 6.22 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 21 22 23 24 25 26 27 28
//
//  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];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -分享
- (IBAction)ShareWeiChatAntWeiboAction:(UIButton *)sender {
    
29 30 31 32 33 34 35 36
    WS(weakSelf);
    if (self.isShareOrderbill) {//分享订单
        [weakSelf CreateMBProgressHUDLoding];
        NSString *shareOrderString = [NSString stringWithFormat:@"%@/%@",SHAREORDERBILL,self.orderBillNumber];
        [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:SERVERREQUESTURL(shareOrderString) WithRequestType:0 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
            
            [weakSelf RemoveMBProgressHUDLoding];
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
曹云霄's avatar
曹云霄 committed
37
                [weakSelf callSharePlatform:returnValue[@"data"][@"url"] withPlatformTag:sender withTitle:@"欧立方订单一键分享"];
38 39 40 41
            }else
            {
                [weakSelf SHOWPrompttext:returnValue[@"message"]];
            }
勾芒's avatar
勾芒 committed
42
            
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
        } WithErrorCodeBlock:^(id errorCodeValue) {
            [weakSelf RemoveMBProgressHUDLoding];
            [weakSelf SHOWPrompttext:NETWORK];
        } WithFailureBlock:^(NSError *error) {
            [weakSelf RemoveMBProgressHUDLoding];
            [weakSelf SHOWPrompttext:error.localizedDescription];
        }];
    }else//分享商品
    {
        [self dismissViewControllerAnimated:YES completion:nil];
        NSData *imageData = UIImageJPEGRepresentation(self.shareImage, 0.5);
        NSString *goodsID = [self.goodsIds substringToIndex:[self.goodsIds length]-1];
        NSDictionary *parameterDict = [NSDictionary dictionaryWithObjectsAndKeys:[goodsID substringToIndex:self.goodsIds.length-1],@"goodsIds",@"",@"title",@"",@"remark",nil];
        //上传图片
        [[NetworkRequestClassManager Manager] UploadImageWithURL:SERVERREQUESTURL(SHARE) WithRequestType:0 WithImageDatas:imageData WithParameter:parameterDict WithReturnValueBlock:^(id returnValue) {
            
            if ([returnValue[@"code"] isEqualToNumber:@0]) {
                
                NSString *shareWeb = returnValue[@"data"][@"url"];
曹云霄's avatar
曹云霄 committed
62
                [weakSelf callSharePlatform:shareWeb withPlatformTag:sender withTitle:ShareTitle];
63 64
            }else
            {
65
                if ([weakSelf.delegate respondsToSelector:@selector(CodeNotEqualZERO:)]) {
勾芒's avatar
勾芒 committed
66
                    
67
                    [weakSelf.delegate CodeNotEqualZERO:returnValue[@"message"]];
勾芒's avatar
勾芒 committed
68
                }
69 70 71 72 73 74 75
            }
            
        }WithprogressBlock:^(double progress) {
            
            if (progress >= 1) {
                
                if ([weakSelf.delegate respondsToSelector:@selector(UploadImageSuccess)]) {
勾芒's avatar
勾芒 committed
76
                    
77
                    [weakSelf.delegate UploadImageSuccess];
勾芒's avatar
勾芒 committed
78
                }
79 80 81 82
                
            }else
            {
                if ([weakSelf.delegate respondsToSelector:@selector(UploadImageProgress:)]) {
勾芒's avatar
勾芒 committed
83
                    
84
                    [weakSelf.delegate UploadImageProgress:progress];
勾芒's avatar
勾芒 committed
85 86
                }
            }
87 88 89 90 91 92
            
        } WithErrorCodeBlock:^(id errorCodeValue) {
            
        } WithFailureBlock:^(NSError *error) {
            
            if ([weakSelf.delegate respondsToSelector:@selector(UploadImageFailue)]) {
曹云霄's avatar
曹云霄 committed
93
                
94
                [weakSelf.delegate UploadImageFailue];
曹云霄's avatar
曹云霄 committed
95
            }
96 97 98 99
            [weakSelf ErrorMBProgressView:error.localizedDescription];
        }];
    }
}
曹云霄's avatar
曹云霄 committed
100

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


@end