美文网首页
分享模块

分享模块

作者: 守护地中海的花 | 来源:发表于2020-03-16 11:43 被阅读0次

先来一波代码

  • SharePopView
//分享
#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;
                }
                //-----------------------------------------
            }
        }];
    }];
}
  • ProductPopPosterView
- (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;
               }
               //-----------------------------------------
           }
       }];
   }];
}

分享图片

  • 设置title、des没有用 无需设置
  • 不可设置link 不然就是链接分享了
  • 必须设置缩略图
  • 如果image 也是[NSDat data]会把微信搞闪退
  • 如果thumbnail设置dataWithContentsOfURL 提示应用内错误
  • 如果thumbnail 不传入提示应用内错误
  • 如果thumnail传入data过大 提示应用内错误msg.thumbnail = UIImagePNGRepresentation([UIImage getJPGimageInBundleWithName:@"high"]); 这是一个大图 如果小图就没有问题
  • image 可以设置本地图片 大小应该不受限制
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.分享链接

  • title、des、link、image、thumbnail
  • 如果不设置image 应用错误
  • 同事设置image 和 thumbnail ,thumnail 会覆盖image
  • 同时设置image 和thumbnail,thumnail设置图片过大 会优先显示image而不错误
  • 同时设置image 话题thumnail,image 设置过大会 会优先显示thumbnail
  • 同时设置image 话题thumnail,image 设置过大会 thumnail设置过大提示应用内报错
  • des可以不分享 但是分享成功后des 就是标题 所以传入@“”空字符串即可默认显示url地址
  • title必须分享
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);
}

相关文章

网友评论

      本文标题:分享模块

      本文链接:https://www.haomeiwen.com/subject/vbxgehtx.html