分享模块

2020-03-16  本文已影响0人  守护地中海的花

先来一波代码

//分享
#import "SharePopView.h"
#import "OpenShareHeader.h"
#import "ProductPopPosterView.h"
- (void)clickShareButton:sender
{
    //if (self.detailModel == nil) {
        //return;
    //}
    WK(weakSelf)
    SharePopView *view = [[SharePopView alloc]initWithFrame:CGRectZero];
    view.parentVC = self;
    //view.containPoster = YES;
    [view setBackPopTypeBlock:^(SharePopType type) {
        BaseShareModel *shareModel = weakSelf.detailModel.data.share;
        [sharedKeyWindow showHudWithContent:@"" withShowTime:10];
        [[SDWebImageDownloader sharedDownloader]downloadImageWithURL:shareModel.image.wppURL completed:^(UIImage * _Nullable thum, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
            if (finished) {
                [sharedKeyWindow hideBusyHUD];
                OSMessage *msg = [[OSMessage alloc]init];
                msg.title = shareModel.title;
                msg.link = shareModel.url;
                msg.desc = IsStrEmpty(shareModel.des) ? @"" : shareModel.des;
                msg.image = UIImagePNGRepresentation(thum);
                //大图片
                if (msg.image.length >= 32 * 1024) {
                    UIImage *imgTemp = [UIImage scaledWithImage:thum scale:CGSizeMake(100, 100)];
                    msg.image = UIImagePNGRepresentation(imgTemp);
                }
                switch (type) {
                    case SharePopTypeWechat:
                    {
                        [OpenShare shareToWeixinSession:msg Success:^(OSMessage *message) {
                            //NSLog(@"%@",message.mj_keyValues);
                        } Fail:^(OSMessage *message, NSError *error) {
                            //NSLog(@"%@ %@",message.mj_keyValues,error);
                        }];
                    }
                        break;
                    case SharePopTypeWechatCircle:
                    {
                        [OpenShare shareToWeixinTimeline:msg Success:^(OSMessage *message) {
                            //NSLog(@"%@",message.mj_keyValues);
                        } Fail:^(OSMessage *message, NSError *error) {
                            //NSLog(@"%@ %@",message.mj_keyValues,error);
                        }];
                    }
                        break;
                    case SharePopTypePoster:
                    {
                        //[weakSelf popPosterView];
                    }
                        break;
                    default:
                        break;
                }
                //-----------------------------------------
            }
        }];
    }];
}
- (void)popPosterView
{
   if (self.detailModel == nil) {
       return;
   }
   WK(weakSelf)
   ProductPopPosterView *view = [[ProductPopPosterView alloc]initWithFrame:CGRectZero];
   view.parentVC = self;
   view.detailModel = self.detailModel;
   [view setBackPopTypeBlock:^(SharePopType type, UIImage * _Nonnull snapshotImage) {
       BaseShareModel *shareModel = weakSelf.detailModel.data.share;
       [sharedKeyWindow showHudWithContent:@"" withShowTime:10];
       [[SDWebImageDownloader sharedDownloader]downloadImageWithURL:shareModel.image.wppURL completed:^(UIImage * _Nullable thum, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
           if (finished) {
               [sharedKeyWindow hideBusyHUD];
               OSMessage *msg = [[OSMessage alloc]init];
               msg.image = UIImagePNGRepresentation(thum);
               msg.thumbnail = [NSData data];
               switch (type) {
                   case SharePopTypeWechat:
                   {
                       [OpenShare shareToWeixinSession:msg Success:^(OSMessage *message) {
                           //NSLog(@"%@",message.mj_keyValues);
                       } Fail:^(OSMessage *message, NSError *error) {
                           //NSLog(@"%@ %@",message.mj_keyValues,error);
                       }];
                   }
                       break;
                   case SharePopTypeWechatCircle:
                   {
                       [OpenShare shareToWeixinTimeline:msg Success:^(OSMessage *message) {
                           //NSLog(@"%@",message.mj_keyValues);
                       } Fail:^(OSMessage *message, NSError *error) {
                           //NSLog(@"%@ %@",message.mj_keyValues,error);
                       }];
                   }
                       break;
                   default:
                       break;
               }
               //-----------------------------------------
           }
       }];
   }];
}

分享图片

OSMessage *msg = [[OSMessage alloc]init];
msg.image = UIImagePNGRepresentation(thum);
msg.thumbnail = [NSData data];

//这样也是可以的
msg.image = [NSData dataWithContentsOfURL:shareModel.image.wppURL];
//也可以设置本地大图片
msg.image = UIImagePNGRepresentation([UIImage getJPGimageInBundleWithName:@"high"]);

2.分享链接

OSMessage *msg = [[OSMessage alloc]init];
msg.title = shareModel.title;
msg.link = shareModel.url;
msg.desc = IsStrEmpty(shareModel.des) ? @"" : shareModel.des;
msg.image = UIImagePNGRepresentation(thum);
//大图片
if (msg.image.length >= 32 * 1024) {
    UIImage *imgTemp = [UIImage scaledWithImage:thum scale:CGSizeMake(100, 100)];
    msg.image = UIImagePNGRepresentation(imgTemp);
}
上一篇 下一篇

猜你喜欢

热点阅读