Commit 1413cdc3 authored by 艾娇平's avatar 艾娇平

分享通用参数处理+图片资源提前下载

parent 4868d66a
......@@ -35,11 +35,12 @@ TODO: Add long description of the pod here.
s.dependency 'Weibo_SDK', '3.2.7'
s.dependency 'DouyinOpenSDK', '1.4.1'
s.dependency 'GMKit'
s.dependency 'MBProgressHUD', '0.9.2'
s.dependency 'MBProgressHUD'
s.dependency 'GMJSONModel'
s.dependency 'GMPhobos'
s.dependency 'GMFoundation'
s.dependency 'Masonry'
s.dependency 'GMHud'
s.frameworks = ['Photos']
s.pod_target_xcconfig = { 'VALID_ARCHS' => 'arm64 armv7 x86_64' }
......
......@@ -13,15 +13,18 @@
@class GMShareView;
@protocol GMDiaryShareViewDelegate <NSObject>
@optional
/** @brief 定制分享定制内容*/
- (NSMutableDictionary *)fetchSharePublishContent:(GMSharePlatform)shareType;
/// 额外的分享数据内容,业务层可根据需求进行修改
/// @param shareType shareType
- (NSDictionary *)extra_shareParams:(GMSharePlatform)shareType;
/** 分享成功 */
- (void)shareResponseSuccess;
/** @brief 分享日记的shareObject*/
- (void)shareObject:(WMShareObject *)object;
@end
@interface GMDiaryShareView : GMView
/** @brief 分享日记的shareObject*/
@property (nonatomic, strong) WMShareObject *object;
/**
连续签到,补签任务
*/
......
......@@ -9,6 +9,7 @@
#import "GMDiaryShareView.h"
#import "GMDiaryShareInfoView.h"
#import "WMShareObject.h"
#import "GMShareConstant.h"
#import <MBProgressHUD/MBProgressHUD.h>
#import <GMPhobos/Phobos.h>
......@@ -117,9 +118,6 @@
[view setShareClickedBlcok:^{
weakSelf.shareUrl = object.shareData.url;
[weakSelf hideShareView];
if ([weakSelf.delegate respondsToSelector:@selector(shareObject:)]) {
[weakSelf.delegate shareObject:object.shareData];
}
[weakSelf shareWithType:GMSharePlatformWechatTimeline];
}];
if (i < diaryArr.count - 1) {
......@@ -136,41 +134,45 @@
[self toast:@"您未安装微信客户端"];
return;
}
NSMutableDictionary *shareParams = [NSMutableDictionary dictionaryWithDictionary:[self.object getShareParams:type]];
//获取定制的分享内容
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
if ([self.delegate respondsToSelector:@selector(fetchSharePublishContent:)]) {
shareParams = [self.delegate fetchSharePublishContent:GMSharePlatformWechatTimeline];
if ([self.delegate respondsToSelector:@selector(extra_shareParams:)]) {
NSDictionary *extra_params = [self.delegate extra_shareParams:GMSharePlatformWechatTimeline];
if (extra_params) {
[shareParams addEntriesFromDictionary:extra_params];
}
}
// 埋点
[self phobosClickShareWithType:type];
[[GMShareSDK shareInstance] share: type parameters:[shareParams mutableCopy] onStateChanged:^(GMShareResponseState state, NSError *error) {
switch (state) {
case GMShareResponseStateBegin:{
// debugLog(@"启动分享");
break;
// debugLog(@"启动分享");
}
break;
case GMShareResponseStateSuccess:{
// debugLog(@"分享成功");
// debugLog(@"分享成功");
if (self) {
if (self.delegate != nil && ![self.delegate isKindOfClass:[NSNull class]]) {
if ([self.delegate respondsToSelector:@selector(shareResponseSuccess)]) {
[self.delegate shareResponseSuccess];
}
}
NSDictionary *dic = @{@"page_name": SafeValue(self.pageName),
@"share_channel": _getGMShareChannelByType(type)};
[Phobos track:@"share_success_statistics" attributes:dic];
}
break;
}
case GMShareResponseStateFail:{
// debugLog(@"分享失败,错误描述:%@", error);
break;
case GMShareResponseStateFail:{
// debugLog(@"分享失败,错误描述:%@", error);
}
case GMShareResponseStateCancel:{
// debugLog(@"取消分享");
break;
case GMShareResponseStateCancel:{
// debugLog(@"取消分享");
}
break;
default:
break;
}
......@@ -184,48 +186,13 @@
NSDictionary *dic = @{@"page_name": SafeValue(phobosView.pageName),
@"business_id": SafeValue(phobosView.businessId),
@"url": SafeValue(self.shareUrl),
@"share_channel": [self channel:type],
@"share_channel": _getGMShareChannelByType(type),
@"task_type":@"diary",
@"business":@"diary_id"
};
@"business":@"diary_id"};
[Phobos track:@"page_click_share_channel" attributes:dic];
}
}
- (NSString *)channel:(GMSharePlatform)type {
NSString *channel = @"";
switch (type) {
case GMSharePlatformWechatSession:
channel = @"wechat";
break;
case GMSharePlatformWechatTimeline:
channel = @"wechatline";
break;
case GMSharePlatformQQFriend:
channel = @"qq";
break;
case GMSharePlatformQQSpace:
channel = @"qzone";
break;
case GMSharePlatformSinaWeibo:
channel = @"tsina";
break;
case GMSharePlatformWechatSessionSnapShot:
channel = @"wechat_snapshot";
break;
case GMSharePlatformWechatTimelineSnapShot:
channel = @"wechatline_snapshot";
break;
case GMSharePlatformCopyLink:
channel = @"copy_url";
break;
default:
channel = @"";
break;
}
return channel;
}
/** * @brief 分享结果提示*/
- (void)toast:(NSString *)text{
[_hud hide:YES];
......
......@@ -23,8 +23,9 @@
- (void)willShowShareView:(GMShareView *)shareView;
@optional
/** @brief 定制分享定制内容*/
- (NSMutableDictionary *)fetchSharePublishContent:(GMSharePlatform)shareType;
/// 额外的分享数据内容,业务层可根据需求进行修改
/// @param shareType shareType
- (NSDictionary *)extra_shareParams:(GMSharePlatform)shareType;
/** @brief 删除*/
- (void)deleteContent;
/** @brief 收藏*/
......@@ -124,7 +125,7 @@
/**
* @author wangyang, 16-01-22 19:01:00
*
* @brief 调用该方法直接分享到指定平台,但仍会走 fetchSharePublishContent 这个代理方法以取得待分享的内容
* @brief 调用该方法直接分享到指定平台
* @param type 将要分享到的平台
* @since 5.9.0
*/
......
......@@ -11,27 +11,18 @@
#import <TencentOpenAPI/QQApiInterface.h>
#import "GMShareFlowLayout.h"
#import "DouyinOpenSDKApi.h"
#import "GMShareConstant.h"
#import <WechatOpenSDK/WXApi.h>
#import <Weibo_SDK/WeiboSDK.h>
#import "GMShareVideoAlertView.h"
#import <GMShareSDK/GMShareSDK.h>
#import <GMKit/GMButton.h>
#import <GMKit/GMLabel.h>
#import <GMPhobos/Phobos.h>
#import <GMPhobos/UIResponder+PhobosPV.h>
#import <GMKit/UIColor+GMTheme.h>
#import <GMKit/Constant.h>
#import <GMKit/GMFont.h>
#import <GMKit/Constant.h>
#import <GMKit/UIView+LineWithAutolayout.h>
#import <GMKit/GMCollectionView.h>
#import <GMFoundation/NSString+GM.h>
#import <GMKit/UIView+SafeArea.h>
#import <GMKit/GMSafeValue.h>
#import <GMKit/UIView+Layout.h>
//#import <GMShareSDK/GMShareSDK-umbrella.h>
@import GMKit;
@import GMPhobos;
@import GMFoundation;
//@import GMPhobos;
static NSString *shareCellIdentifier = @"shareCellIdentifier";
......@@ -405,12 +396,16 @@ static NSString *shareCellIdentifier = @"shareCellIdentifier";
}
- (void)goToShareWithType:(GMSharePlatform)type {
NSMutableDictionary *shareParams = [NSMutableDictionary dictionaryWithDictionary:[self.shareObject getShareParams:type]];
//获取定制的分享内容
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
if ([self.delegate respondsToSelector:@selector(fetchSharePublishContent:)]) {
shareParams = [self.delegate fetchSharePublishContent:type];
if ([self.delegate respondsToSelector:@selector(extra_shareParams:)]) {
NSDictionary *extra_params = [self.delegate extra_shareParams:GMSharePlatformWechatTimeline];
if (extra_params) {
[shareParams addEntriesFromDictionary:extra_params];
}
}
// 埋点
[self phobosClickShareWithType:type];
[[GMShareSDK shareInstance] share: type parameters:[shareParams mutableCopy] onStateChanged:^(GMShareResponseState state, NSError *error) {
......@@ -431,7 +426,7 @@ static NSString *shareCellIdentifier = @"shareCellIdentifier";
if ([self.delegate isKindOfClass:[UIResponder class]] && self.isReportShareResult) {
UIResponder *phobosView = (UIResponder *)self.delegate;
NSDictionary *dic = @{@"page_name": SafeValue(phobosView.pageName),
@"share_channel": [self channel:type]};
@"share_channel": _getGMShareChannelByType(type)};
[Phobos track:@"share_success_statistics" attributes:dic];
}
break;
......@@ -450,47 +445,6 @@ static NSString *shareCellIdentifier = @"shareCellIdentifier";
}];
}
- (NSString *)channel:(GMSharePlatform)type {
NSString *channel = @"";
switch (type) {
case GMSharePlatformWechatSession:
channel = @"wechat";
break;
case GMSharePlatformWechatTimeline:
channel = @"wechatline";
break;
case GMSharePlatformQQFriend:
channel = @"qq";
break;
case GMSharePlatformQQSpace:
channel = @"qzone";
break;
case GMSharePlatformSinaWeibo:
channel = @"tsina";
break;
case GMSharePlatformWechatSessionSnapShot:
channel = @"wechat_snapshot";
break;
case GMSharePlatformWechatTimelineSnapShot:
channel = @"wechatline_snapshot";
break;
case GMSharePlatformCopyLink:
channel = @"copy_url";
break;
case GMSharePlatformDouyin:
channel = @"douyin";
break;
default:
channel = @"";
break;
}
return channel;
}
- (void)dealloc {
}
/**
* @brief 分享界面的有关动画
添加上滑动画
......@@ -569,7 +523,7 @@ static NSString *shareCellIdentifier = @"shareCellIdentifier";
NSDictionary *dic = @{@"page_name": SafeString(pageName),
@"business_id": SafeString(businessId),
@"url": SafeString(self.shareUrl),
@"share_channel": [self channel:type],
@"share_channel": _getGMShareChannelByType(type),
@"task_type":SafeString(self.taskType),
@"business":@"channel"};
[Phobos track:@"page_click_share_channel" attributes:dic];
......
//
// WMWeixinShareView.h
// Gengmei
//
// Created by Sean Lee on 7/6/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "WMShareObject.h"
#import "GMShareConstant.h"
@interface GMWeixinShareView : UIView
@property (nonatomic, strong) WMShareObject *weixinShareObject;
/// shareBlock
@property (nonatomic, copy) GMSharePlatformClick platformClick;
/**
* @author licong, 16-01-08 14:01:38
*
* 实例化一个WMWeixinShareView
*
* @return 返回一个实例化成功的shareView
*
* @since 5.8.0
*/
+ (GMWeixinShareView *)shareView;
/**
* @author licong, 16-01-08 14:01:46
*
* 弹出微信分享框
*
* @since 5.8.0
*/
- (void)showShareView:(id)sender;
/**
* @author licong, 16-01-08 14:01:46
*
* 隐藏微信分享框
*
* @since 5.8.0
*/
- (IBAction)hideShareView:(id)sender;
@end
//
// WMWeixinShareView.m
// Gengmei
//
// Created by Sean Lee on 7/6/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "GMWeixinShareView.h"
#import "NSMutableDictionary+GMShareSDK.h"
#import "GMShareSDK.h"
#import "GMShareConstant.h"
@import GMPhobos;
@import GMKit;
@import GMFoundation;
@interface GMWeixinShareView ()
@property (weak, nonatomic) IBOutlet UITapGestureRecognizer *tapGestureRecognizer;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *shareViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *shareViewHeight;
@end
@implementation GMWeixinShareView
+ (GMWeixinShareView *)shareView{
GMWeixinShareView *shareView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([GMWeixinShareView class]) owner:nil options:nil].firstObject;
shareView.shareViewHeight.constant = UIDevice.aspectRatioType == GMDeviceAspectRatioTypeWide ? 184 : 150;
return shareView;
}
- (IBAction)shareButtonClicked:(UIButton *)button{
[self hideShareView:nil];
GMSharePlatform type = (GMSharePlatform)button.tag;
//分享埋点
[self weixin_click_share_channel:type];
if (self.platformClick) {
self.platformClick(type);
}
}
- (void)showShareView:(id)sender {
self.hidden = NO;
self.tapGestureRecognizer.enabled = YES;
[UIView animateWithDuration:0.25 animations:^{
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
self.shareViewBottomConstraint.constant = [UIDevice aspectRatioType] == GMDeviceAspectRatioTypeWide ? 184 : 150;
[self layoutIfNeeded];
}];
}
- (IBAction)hideShareView:(id)sender {
self.tapGestureRecognizer.enabled = NO;
[UIView animateWithDuration:0.25 animations:^{
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
self.shareViewBottomConstraint.constant = 0;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
self.hidden = YES;
}];
}
//埋点
- (void)weixin_click_share_channel:(NSInteger)type {
//type 3-微信好友, 4-朋友圈
[Phobos track:@"weixin_click_share_channel" attributes:@{
@"share_channel" : type == 3 ? @"微信好友" : @"朋友圈",
@"from" : self.weixinShareObject.from.isNonEmpty ? self.weixinShareObject.from : @""}];
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="GMWeixinShareView">
<rect key="frame" x="0.0" y="0.0" width="320" height="477"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="e19-GG-RSd" userLabel="ShareView">
<rect key="frame" x="0.0" y="477" width="320" height="150"/>
<subviews>
<button opaque="NO" tag="3" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VXP-M0-7VD">
<rect key="frame" x="50" y="20" width="60" height="80"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="nFW-kO-27w"/>
<constraint firstAttribute="height" constant="80" id="qPS-so-nCr"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<inset key="titleEdgeInsets" minX="-54" minY="45" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="0.0" minY="-30" maxX="0.0" maxY="0.0"/>
<state key="normal" title="微信" image="share_weixin_coupon_timeline">
<color key="titleColor" red="0.1919802725315094" green="0.19197453558444977" blue="0.19197782874107361" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="shareButtonClicked:" destination="iN0-l3-epB" eventType="touchUpInside" id="SKU-RI-DN7"/>
</connections>
</button>
<button opaque="NO" tag="4" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vec-Bd-FiL">
<rect key="frame" x="210" y="20" width="60" height="80"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="tBd-jr-WiX"/>
<constraint firstAttribute="width" constant="60" id="xec-Pb-tRj"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<inset key="titleEdgeInsets" minX="-54" minY="45" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="0.0" minY="-30" maxX="0.0" maxY="0.0"/>
<state key="normal" title="朋友圈" image="share_weixin_coupon_session">
<color key="titleColor" red="0.1919802725315094" green="0.19197453558444977" blue="0.19197782874107361" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="shareButtonClicked:" destination="iN0-l3-epB" eventType="touchUpInside" id="hLT-nh-rsY"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wYr-DV-cwz">
<rect key="frame" x="0.0" y="105" width="320" height="0.5"/>
<color key="backgroundColor" red="0.89803921568627454" green="0.89803921568627454" blue="0.89803921568627454" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="0.5" id="7i2-t4-rvw"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4Su-Dy-ilU">
<rect key="frame" x="0.0" y="105.5" width="320" height="45"/>
<constraints>
<constraint firstAttribute="height" constant="45" id="7Tb-js-ozy"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<state key="normal" title="取消">
<color key="titleColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
</state>
<state key="highlighted" title="取消"/>
<connections>
<action selector="hideShareView:" destination="iN0-l3-epB" eventType="touchUpInside" id="GT5-mj-zqx"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="VXP-M0-7VD" firstAttribute="top" secondItem="e19-GG-RSd" secondAttribute="top" constant="20" id="0LA-qZ-jO0"/>
<constraint firstAttribute="trailing" secondItem="wYr-DV-cwz" secondAttribute="trailing" id="0OS-a5-NqZ"/>
<constraint firstAttribute="trailing" secondItem="4Su-Dy-ilU" secondAttribute="trailing" id="4j0-hz-Ii1"/>
<constraint firstItem="4Su-Dy-ilU" firstAttribute="top" secondItem="wYr-DV-cwz" secondAttribute="bottom" id="8Fr-X0-agM"/>
<constraint firstAttribute="height" constant="150" id="G4L-wV-57D"/>
<constraint firstItem="wYr-DV-cwz" firstAttribute="top" secondItem="VXP-M0-7VD" secondAttribute="bottom" constant="5" id="MYZ-ht-LUU"/>
<constraint firstItem="wYr-DV-cwz" firstAttribute="leading" secondItem="e19-GG-RSd" secondAttribute="leading" id="Q9m-oc-cLH"/>
<constraint firstItem="4Su-Dy-ilU" firstAttribute="leading" secondItem="e19-GG-RSd" secondAttribute="leading" id="VcO-ea-Stl"/>
<constraint firstItem="vec-Bd-FiL" firstAttribute="centerY" secondItem="VXP-M0-7VD" secondAttribute="centerY" id="g2M-AC-jmC"/>
<constraint firstItem="VXP-M0-7VD" firstAttribute="centerX" secondItem="e19-GG-RSd" secondAttribute="centerX" multiplier="0.5" id="sZS-6i-r8i"/>
<constraint firstItem="vec-Bd-FiL" firstAttribute="centerX" secondItem="e19-GG-RSd" secondAttribute="centerX" multiplier="1.5" id="tTz-f7-lW2"/>
</constraints>
</view>
</subviews>
<gestureRecognizers/>
<constraints>
<constraint firstItem="e19-GG-RSd" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="3vb-UQ-qgW"/>
<constraint firstAttribute="bottom" secondItem="e19-GG-RSd" secondAttribute="top" id="8Lk-fD-Nqk"/>
<constraint firstAttribute="trailing" secondItem="e19-GG-RSd" secondAttribute="trailing" id="Kfi-de-oGC"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="shareViewBottomConstraint" destination="8Lk-fD-Nqk" id="ici-eC-Dn2"/>
<outlet property="shareViewHeight" destination="G4L-wV-57D" id="wJ9-fa-gXu"/>
<outlet property="tapGestureRecognizer" destination="oVa-0W-Y9X" id="gGA-x7-d6g"/>
<outletCollection property="gestureRecognizers" destination="oVa-0W-Y9X" appends="YES" id="dwu-oR-kfy"/>
</connections>
<point key="canvasLocation" x="34" y="52.5"/>
</view>
<tapGestureRecognizer id="oVa-0W-Y9X">
<connections>
<action selector="hideShareView:" destination="iN0-l3-epB" id="u6P-tD-Oex"/>
<outlet property="delegate" destination="e19-GG-RSd" id="Rq5-aq-lJA"/>
</connections>
</tapGestureRecognizer>
</objects>
<resources>
<image name="share_weixin_coupon_session" width="45" height="45"/>
<image name="share_weixin_coupon_timeline" width="45" height="45"/>
</resources>
</document>
......@@ -6,7 +6,7 @@
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "GMShareBaseObject.h"
//#import <GMBase/GMObject.h>
#import "GMThirdPartyDefine.h"
@protocol WMShareBasicObject @end
@interface WMShareBasicObject : GMShareBaseObject
......@@ -22,6 +22,31 @@
@property (nonatomic,strong) NSString * path;
@property (nonatomic,strong) NSString * userName;
@property (nonatomic,strong) NSString * thumbImageUrl;
@property (nonatomic,strong) UIImage *hdImage;
@property (nonatomic,strong) UIImage *thumbImage;
@end
@protocol GMCoverObject @end
@interface GMCoverObject : GMShareBaseObject
@property (nonatomic,strong) NSString * desc;
@property (nonatomic,strong) NSString * image;
@end
@protocol GMOthersObject @end
@interface GMOthersObject : GMShareBaseObject
@property (nonatomic,strong) NSString * cityName;
@property (nonatomic,strong) NSArray<GMCoverObject> * cover;
@property (nonatomic,strong) NSString * title;
@property (nonatomic,strong) NSString * type;
@property (nonatomic,strong) NSString * path;
@property (nonatomic,strong) NSString * voteNum;
@property (nonatomic,strong) NSString * voteNumDesc;
@property (nonatomic,strong) NSString * beforeDesc;
@property (nonatomic,strong) NSString * afterCoverUrl;
@property (nonatomic,strong) NSString * afterDesc;
@property (nonatomic,strong) NSString * beforeCoverUrl;
@property (nonatomic,strong) UIImage *afterCoverImage;
@property (nonatomic,strong) UIImage *beforeCoverImage;
@end
......@@ -42,11 +67,17 @@
@property (nonatomic,strong) WMShareBasicObject <WMShareBasicObject>* weibo;
@property (nonatomic,strong) GMWechatminiObject <GMWechatminiObject>* wechatmini;
@property (nonatomic,strong) WMShareBasicObject <WMShareBasicObject>* douyin; // 分享到抖音 扫脸1.5
@property (nonatomic,strong) GMOthersObject <GMWechatminiObject>* others;
@property (nonatomic, copy) NSString *page_name;// 埋点使用
@property (nonatomic, copy) NSString *business_id;// 埋点使用
@property (nonatomic, copy) NSString *is_like;//埋点使用
@property (nonatomic, copy) NSString *videoUrl;//视频URL(分享视频时)扫脸1.5
@property (nonatomic, assign) GMShareContentType contentType;
@property (nonatomic, strong) UIImage *shareImage;
@property (nonatomic, assign) GMSharePlatform platform;/// 分享平台
/// 获取分享通用数据
/// @param shareType shareType
- (NSMutableDictionary *)getShareParams:(GMSharePlatform)shareType;
@end
@protocol GMDiaryShareObject @end
......
......@@ -7,7 +7,9 @@
//
#import "WMShareObject.h"
#import "NSMutableDictionary+GMShareSDK.h"
@import GMFoundation;
@import SDWebImage;
@implementation WMShareBasicObject
......@@ -16,11 +18,167 @@
@implementation GMWechatminiObject
// 获取到图片地址后,进行优先图片下载
- (void)setHdImageUrl:(NSString *)hdImageUrl {
_hdImageUrl = hdImageUrl;
self.thumbImage = [UIImage imageNamed:@"icon"];
if (hdImageUrl.length) {
__weak typeof(self) weakSelf = self;
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:hdImageUrl] completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image) {
weakSelf.hdImage = image;
}
}];
}
}
- (void)setThumbImageUrl:(NSString *)thumbImageUrl {
_thumbImageUrl = thumbImageUrl;
self.thumbImage = [UIImage imageNamed:@"share_smallProgram"];
if (thumbImageUrl.length) {
__weak typeof(self) weakSelf = self;
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:thumbImageUrl] completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image) {
weakSelf.thumbImage = image;
}
}];
}
}
@end
@implementation GMCoverObject
@end
@implementation GMOthersObject
- (void)setAfterCoverUrl:(NSString *)afterCoverUrl {
_afterCoverUrl = afterCoverUrl;
if (!afterCoverUrl.isNonEmpty) {
return;
}
__weak typeof(self) weakSelf = self;
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:afterCoverUrl] completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image) {
weakSelf.afterCoverImage = image;
}
}];
}
- (void)setBeforeCoverUrl:(NSString *)beforeCoverUrl {
_beforeCoverUrl = beforeCoverUrl;
if (!beforeCoverUrl.isNonEmpty) {
return;
}
__weak typeof(self) weakSelf = self;
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:beforeCoverUrl] completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image) {
weakSelf.beforeCoverImage = image;
}
}];
}
@end
@implementation WMShareObject
- (void)setImage:(NSString *)image {
_image = image;
if (image.length) {
__weak typeof(self) weakSelf = self;
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:image] completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image) {
weakSelf.shareImage = image;
}
}];
}
}
- (void)setPlatform:(GMSharePlatform)platform {
_platform = platform;
switch (platform) {
case GMSharePlatformWechatSessionSnapShot:
case GMSharePlatformWechatTimelineSnapShot:
{
self.shareImage = self.wechatScreenshot.content;
self.contentType = GMShareContentTypeImage;
}
break;
default:
{
self.contentType = GMShareContentTypeAuto;
}
break;
}
}
/// 获取分享通用数据
/// @param shareType 分享平台
- (NSMutableDictionary *)getShareParams:(GMSharePlatform)shareType {
self.platform = shareType;
WMShareBasicObject *object = nil;
UIImage *shareImage = self.shareImage?:[UIImage imageNamed:@"icon"];
// 微信会话分享且微信小程序内容不为空的时候,认为是微信小程序分享
if (shareType == GMSharePlatformWechatSession && self.wechatmini.path.length) {
shareType = GMSharePlatformWechatMiniProgram;
}
switch (shareType) {
case GMSharePlatformWechatSession:
object = self.wechat;
break;
case GMSharePlatformWechatTimeline:
object = self.wechatline;
break;
case GMSharePlatformWechatMiniProgram:
object = self.wechatmini;
break;
case GMSharePlatformQQFriend:
object = self.qq;
break;
case GMSharePlatformQQSpace:
object = self.qqzone;
break;
case GMSharePlatformSinaWeibo:
object = self.weibo;
break;
case GMSharePlatformDouyin:
object = self.douyin;
break;
case GMSharePlatformWechatSessionSnapShot:
object = self.wechatScreenshot;
shareImage = self.wechatScreenshot.content;
break;
case GMSharePlatformWechatTimelineSnapShot:
object = self.wechatlineScreenshot;
shareImage = self.wechatlineScreenshot.content;
break;
default:
break;
}
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
if (shareType == GMSharePlatformWechatMiniProgram) {
[shareParams shareSetupMiniProgramShareParamsByUrl:self.url
userName:self.wechatmini.userName
path:self.wechatmini.path
title:self.wechatmini.title
description:self.wechatmini.desc
thumbImage:self.wechatmini.thumbImage
hdImageData:self.wechatmini.hdImage];
} else {
if (self.videoUrl.length) {
// 分享视频
[shareParams shareSetupShareParamsByText:object.content images:shareImage url:[NSURL URLWithString:self.url] title:object.title videoUrl:[NSURL URLWithString:self.videoUrl] type:self.contentType];
} else {
[shareParams shareSetupShareParamsByText:object.content
images:shareImage
url:[NSURL URLWithString:self.url]
title:object.title
type:self.contentType];
}
}
return shareParams;
}
@end
@implementation GMDiaryShareObject
......
//
// GMShareConstant.h
// GMShareSDK
//
// Created by Mikasa on 2021/1/15.
//
#import "GMThirdPartyDefine.h"
typedef void(^GMSharePlatformClick)(GMSharePlatform platform);
extern NSString * const ShareContentType;
extern NSString * const ShareOnlyImage;
extern NSString * const ShareImage;
extern NSString * const ShareUrl;
extern NSString * const ShareTitle;
extern NSString * const ShareText;
extern NSString * const ShareUserName;
extern NSString * const SharePath;
extern NSString * const ShareHdImageData;
extern NSString * const ShareDescription;
extern NSString * const ShareThumbImage;
extern NSString * const ShareVideoUrl;
// 获取分享平台渠道---埋点使用
static inline NSString *_getGMShareChannelByType(GMSharePlatform platformType) {
if (platformType & GMSharePlatformQQFriend) return @"qq";
if (platformType & GMSharePlatformQQSpace) return @"qzone";
if (platformType & GMSharePlatformWechatSession) return @"wechat";
if (platformType & GMSharePlatformWechatTimeline) return @"wechatline";
if (platformType & GMSharePlatformWechatSessionSnapShot) return @"wechat_snapshot";
if (platformType & GMSharePlatformWechatTimelineSnapShot) return @"wechatline_snapshot";
if (platformType & GMSharePlatformWechatMiniProgram) return @"xcx";
if (platformType & GMSharePlatformSinaWeibo) return @"tsina";
if (platformType & GMSharePlatformDouyin) return @"Douyin";
if (platformType & GMSharePlatformCopyLink) return @"copy_url";
return @"Default";
}
//
// GMShareConstant.m
// GMShareSDK
//
// Created by Mikasa on 2021/1/15.
//
NSString * const ShareContentType = @"type";
NSString * const ShareOnlyImage = @"onlyImage";
NSString * const ShareImage = @"image";
NSString * const ShareUrl = @"url";
NSString * const ShareTitle = @"title";
NSString * const ShareText = @"text";
NSString * const ShareUserName = @"userName";
NSString * const SharePath = @"path";
NSString * const ShareHdImageData = @"hdImageData";
NSString * const ShareDescription = @"description";
NSString * const ShareThumbImage = @"thumbImage";
NSString * const ShareVideoUrl = @"videoUrl";
......@@ -13,7 +13,6 @@
* 分享内容状态变更回调处理器
*
* @param state 状态
* @param userData 附加数据, 返回状态以外的一些数据描述,如:邮件分享取消时,标识是否保存草稿等
* @param error 错误信息,当且仅当state为SSDKResponseStateFail时返回
*/
typedef void(^GMSDKShareStateChangedHandler) (GMShareResponseState state, NSError *error);
......@@ -25,12 +24,8 @@ typedef void(^GMSDKShareStateChangedHandler) (GMShareResponseState state, NSErr
/** 判断微博、微信、QQ是否已经安装*/
+ (BOOL)isClientInstalled:(GMSharePlatform)platformType;
+ (UIImage *)compressWithUrl:(NSString *)url;
+ (UIImage *)compressImage:(UIImage *)image;
+ (NSString *)shareChannel:(GMSharePlatform)platformType;
- (void)share:(GMSharePlatform)platformType
parameters:(NSMutableDictionary *)parameters
onStateChanged:(GMSDKShareStateChangedHandler)stateChangedHandler;
......
......@@ -22,6 +22,9 @@
#import "DouyinOpenSDKApi.h"
#import "UIAlertController+gm.h"
#import <WechatOpenSDK/WXApi.h>
#import "GMShareConstant.h"
@import SDWebImage;
@interface GMShareSDK ()
#warning TODO 待验证
......@@ -33,8 +36,7 @@
@implementation GMShareSDK
+ (instancetype)shareInstance
{
+ (instancetype)shareInstance {
static dispatch_once_t onceToken;
static id instance = nil;
dispatch_once(&onceToken, ^{
......@@ -49,7 +51,9 @@
platformType == GMSharePlatformQQSpace ||
platformType == GMSharePlatformQQFriend) {
return [QQApiInterface isQQInstalled] ? YES : NO;
} else if ((platformType == GMSharePlatformWechatTimeline) | (platformType == GMSharePlatformWechatSession) | (platformType == GMSharePlatformWechat)) {
} else if (platformType == GMSharePlatformWechatTimeline ||
platformType == GMSharePlatformWechatSession ||
platformType == GMSharePlatformWechat) {
return [WXApi isWXAppInstalled] ? YES : NO;
} else if (platformType == GMSharePlatformSinaWeibo){
return [WeiboSDK isWeiboAppInstalled] ? YES : NO;
......@@ -60,66 +64,7 @@
}
}
// 获取分享平台渠道(H5 埋点使用)
+ (NSString *)shareChannel:(GMSharePlatform)platformType {
switch (platformType) {
case GMSharePlatformQQFriend:{
return @"qq";
}
break;
case GMSharePlatformQQSpace:{
return @"qzone";
break;
}
case GMSharePlatformWechatSession:{
return @"wechat";
break;
}
case GMSharePlatformWechatTimeline:{
return @"wechatline";
break;
}
case GMSharePlatformWechatSessionSnapShot:{
return @"wechat_snapshot";
break;
}
case GMSharePlatformWechatTimelineSnapShot:{
return @"wechatline_snapshot";
break;
}
case GMSharePlatformWechatMiniProgram:{
return @"xcx";
break;
}
case GMSharePlatformSinaWeibo:{
return @"tsina";
break;
}
case GMSharePlatformDouyin:{
return @"Douyin";
break;
}
default:
return @"Default";
break;
}
}
//TODO 换一种方式压缩图片
+ (UIImage *)compressWithUrl:(NSString *)url{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1.5];
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
UIImage* image = [UIImage imageWithData: data];
//如果远程的图片下载不下来,则使用默认图
if (image == nil) {
image = [UIImage imageNamed:@"icon"];
}
image = [GMShareSDK compressImage:image];
return image;
}
#pragma mark - Image Utils
+ (UIImage *)compressImage:(UIImage *)image{
// 图片下载成功后,分享到微信的图片不能太大
if (image.size.width * image.size.height> 300 * 300) {
......@@ -129,26 +74,27 @@
return image;
}
#pragma mark - share parameters
- (void)share:(GMSharePlatform)platformType parameters:(NSMutableDictionary *)parameters onStateChanged:(GMSDKShareStateChangedHandler)stateChangedHandler{
GMShareContentType contentType = (GMShareContentType)[parameters[@"type"] integerValue];
GMShareContentType contentType = (GMShareContentType)[parameters[ShareContentType] integerValue];
if (contentType == GMShareContentTypeMiniProgram) {
platformType = GMSharePlatformWechatMiniProgram;
}
switch (platformType) {
case GMSharePlatformQQFriend:{
if (parameters[@"onlyImage"]) {
[[GMShareSDK shareInstance] shareImage:parameters[@"image"] platform:platformType];
if (parameters[ShareOnlyImage]) {
[self shareImage:parameters[ShareImage] platform:platformType];
} else {
[self QQFriendShareWithParameters:parameters];
}
[self shareWithName:kQQShare onStateChanged:stateChangedHandler];
}
break;
case GMSharePlatformQQSpace:{
if (parameters[@"onlyImage"]) {
[[GMShareSDK shareInstance] shareImage:parameters[@"image"] platform:platformType];
if (parameters[ShareOnlyImage]) {
[self shareImage:parameters[ShareImage] platform:platformType];
} else {
[self QQSpaceShareWithParameters:parameters];
}
......@@ -156,8 +102,8 @@
break;
}
case GMSharePlatformWechatSession:{
if (parameters[@"onlyImage"]) {
[[GMShareSDK shareInstance] shareImage:parameters[@"image"] platform:platformType];
if (parameters[ShareOnlyImage]) {
[self shareImage:parameters[ShareImage] platform:platformType];
} else {
[self wechatSessionShareWithParameters:parameters scene:WXSceneSession];
}
......@@ -165,32 +111,24 @@
break;
}
case GMSharePlatformWechatTimeline:{
if (parameters[@"onlyImage"]) {
[[GMShareSDK shareInstance] shareImage:parameters[@"image"] platform:platformType];
if (parameters[ShareOnlyImage]) {
[self shareImage:parameters[ShareImage] platform:platformType];
} else {
[self wechatSessionShareWithParameters:parameters scene:WXSceneTimeline];
}
[self shareWithName:kWechatShare onStateChanged:stateChangedHandler];
break;
}
case GMSharePlatformWechatSessionSnapShot:{
[self wechatSessionShareWithParameters:parameters scene:WXSceneSession];
[self shareWithName:kWechatShare onStateChanged:stateChangedHandler];
break;
}
case GMSharePlatformWechatTimelineSnapShot:{
[self wechatSessionShareWithParameters:parameters scene:WXSceneTimeline];
[self shareWithName:kWechatShare onStateChanged:stateChangedHandler];
break;
}
case GMSharePlatformWechatSessionSnapShot:
case GMSharePlatformWechatTimelineSnapShot:
case GMSharePlatformWechatMiniProgram:{
[self wechatSessionShareWithParameters:parameters scene:WXSceneSession];
[self shareWithName:kWechatShare onStateChanged:stateChangedHandler];
break;
}
case GMSharePlatformSinaWeibo:{
if (parameters[@"onlyImage"]) {
[[GMShareSDK shareInstance] shareImage:parameters[@"image"] platform:platformType];
if (parameters[ShareOnlyImage]) {
[[GMShareSDK shareInstance] shareImage:parameters[ShareImage] platform:platformType];
} else {
[self weiboShareWithParameters:parameters];
}
......@@ -236,22 +174,21 @@
[self QZoneShareWithImage:image];
}
break;
case GMSharePlatformWechatSession: {
[self wechatImageShareWithParameters:@{@"images": image} scene:WXSceneSession];
[self wechatImageShareWithParameters:@{ShareImage: image} scene:WXSceneSession];
}
break;
case GMSharePlatformWechatTimeline:{
[self wechatImageShareWithParameters:@{@"images": image} scene:WXSceneTimeline];
[self wechatImageShareWithParameters:@{ShareImage: image} scene:WXSceneTimeline];
}
break;
case GMSharePlatformSinaWeibo:{
[self weiboShareWithParameters:@{@"images": image}];
[self weiboShareWithParameters:@{ShareImage: image}];
}
break;
default:
break;
}
......@@ -296,12 +233,11 @@
}
- (void)QQFriendShareWithParameters: (NSDictionary *)parameters {
id image = parameters[@"images"];
UIImage * thumbImage = image;
UIImage * thumbImage = parameters[ShareImage]?:[UIImage imageNamed:@"icon"];
NSURL* url = parameters[@"url"];
NSString *title = parameters[@"title"];
NSString *description = parameters[@"text"];
NSURL* url = parameters[ShareUrl];
NSString *title = parameters[ShareTitle];
NSString *description = parameters[ShareText];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:title description:description previewImageData:UIImagePNGRepresentation(thumbImage)];
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
......@@ -314,16 +250,16 @@
- (void)QQSpaceShareWithParameters: (NSDictionary *)parameters {
UIImage * previewImage = nil;
id images = parameters[@"images"];
id images = parameters[ShareImage]?:[UIImage imageNamed:@"icon"];
if ([images isKindOfClass:[NSArray class]]) {
NSArray * tmp = (NSArray *)images;
previewImage = tmp.firstObject;
} else {
previewImage = images;
}
NSURL* url = parameters[@"url"];
NSString *title = parameters[@"title"];
NSString *description = parameters[@"text"];
NSURL* url = parameters[ShareUrl];
NSString *title = parameters[ShareTitle];
NSString *description = parameters[ShareText];
NSData *data = UIImagePNGRepresentation(previewImage);
QQApiNewsObject * imgObj = [QQApiNewsObject objectWithURL:url title:title description:description previewImageData:data];
[imgObj setTitle:title ? : @""];
......@@ -422,9 +358,8 @@
}
- (WBMessageObject *)manageWeiboMessageWithParameters: (NSDictionary *)parameters{
id image = parameters[@"images"];
UIImage * thumbImage = image;
NSString *description = parameters[@"text"];
UIImage * thumbImage = parameters[ShareImage]?:[UIImage imageNamed:@"icon"];
NSString *description = parameters[ShareText];
WBMessageObject *message = [WBMessageObject message];
message.text = description;
WBImageObject *imageObject = [WBImageObject object];
......@@ -436,7 +371,7 @@
return message;
}
-(void)wbsdk_TransferDidReceiveObject:(id)object{
- (void)wbsdk_TransferDidReceiveObject:(id)object{
[self messageShare];
}
......@@ -445,10 +380,10 @@
#pragma mark -- weChatShare
- (void)wechatSessionShareWithParameters: (NSDictionary *)parameters scene:(int)scene {
GMShareContentType contentType = (GMShareContentType)[parameters[@"type"] integerValue];
GMShareContentType contentType = (GMShareContentType)[parameters[ShareContentType] integerValue];
switch (contentType) {
case GMShareContentTypeAuto:{
NSURL* url = parameters[@"url"];
case GMShareContentTypeAuto: {
NSURL* url = parameters[ShareUrl];
if (url) {
[self wechatLinkShareWith:parameters scene:scene];
} else {
......@@ -456,26 +391,27 @@
}
}
break;
case GMShareContentTypeText:
break;
case GMShareContentTypeImage:
{
[self wechatImageShareWithParameters:parameters scene:scene];
}
break;
case GMShareContentTypeWebPage:
{
[self wechatLinkShareWith:parameters scene:scene];
}
break;
case GMShareContentTypeAudio:
case GMShareContentTypeMiniProgram:
{
[self wechatMiniProgramWithParameters:parameters scene:scene];
}
break;
case GMShareContentTypeAudio:
case GMShareContentTypeVideo:
break;
case GMShareContentTypeFile:
break;
case GMShareContentTypeFBMessageImages:
break;
case GMShareContentTypeFBMessageVideo:
break;
case GMShareContentTypeMiniProgram:
[self wechatMiniProgramWithParameters:parameters scene:scene];
case GMShareContentTypeText:
break;
default:
break;
......@@ -485,19 +421,19 @@
- (void)wechatMiniProgramWithParameters: (NSDictionary *)parameters scene:(int)scene {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
WXMiniProgramObject *wxMiniObject = [WXMiniProgramObject object];
wxMiniObject.webpageUrl = parameters[@"url"];
wxMiniObject.userName = parameters[@"userName"];
wxMiniObject.path = parameters[@"path"];
wxMiniObject.webpageUrl = parameters[ShareUrl];
wxMiniObject.userName = parameters[ShareUserName];
wxMiniObject.path = parameters[SharePath];
// 压缩图片(不大于128K)
NSData * hdImageData = [self requesDataWithString:parameters[@"hdImageData"]];
hdImageData = [UIImage compressImage:[UIImage imageWithData:hdImageData] toByte:128 * 1024 size:CGSizeMake(300, 240)];
UIImage *hdImage = parameters[ShareHdImageData]?:[UIImage imageNamed:@"share_smallProgram"];
NSData * hdImageData = [UIImage compressImage:hdImage toByte:128 * 1024 size:CGSizeMake(300, 240)];
wxMiniObject.hdImageData = hdImageData;
WXMediaMessage *message = [WXMediaMessage message];
message.title = parameters[@"title"];
message.description = parameters[@"description"];
message.title = parameters[ShareTitle];
message.description = parameters[ShareDescription];
message.mediaObject = wxMiniObject;
UIImage * thumbImage = [self originalImageWithString:parameters[@"thumbImage"]];
UIImage *thumbImage = parameters[ShareThumbImage]?:[UIImage imageNamed:@"icon"];
thumbImage = [UIImage imageWithData:[UIImage compressImage:thumbImage toByte:32 * 1024 size:CGSizeMake(150, 150)]];
[message setThumbImage:thumbImage];
SendMessageToWXReq * req = [[SendMessageToWXReq alloc]init];
......@@ -512,9 +448,8 @@
});
}
- (void)wechatImageShareWithParameters: (NSDictionary *)parameters scene:(int)scene{
id string = parameters[@"images"];
UIImage * originlaImage = [self originalImageWithString:string];
- (void)wechatImageShareWithParameters: (NSDictionary *)parameters scene:(int)scene {
UIImage * originlaImage = parameters[ShareImage]?:[UIImage imageNamed:@"icon"];
WXImageObject *ext = [WXImageObject object];
ext.imageData = UIImagePNGRepresentation(originlaImage);
//如果图片大于10M 需要对图片压缩
......@@ -534,11 +469,11 @@
- (void)wechatLinkShareWith:(NSDictionary *)parameters scene:(int)scene{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
id image = parameters[@"images"];
id image = parameters[ShareImage];
UIImage * thumbImage = image;
NSURL* url = parameters[@"url"];
NSString *title = parameters[@"title"];
NSString *description = parameters[@"text"];
NSURL* url = parameters[ShareUrl];
NSString *title = parameters[ShareTitle];
NSString *description = parameters[ShareText];
WXWebpageObject *ext = [WXWebpageObject object];
ext.webpageUrl = url.absoluteString;
......@@ -557,48 +492,6 @@
});
}
- (UIImage *)originalImageWithString:(id )string{
UIImage* image = nil;
if ([string isKindOfClass:[UIImage class]]){
image = (UIImage *)string;
} else if ([string isKindOfClass:[NSString class]]) {
NSString *url = (NSString *)string;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1.5];
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
image = [UIImage imageWithData: data];
//如果远程的图片下载不下来,则使用默认图
if (image == nil) {
image = [UIImage imageNamed:@"icon"];
}
}
return image;
}
- (NSData *)requesDataWithString:(id)string{
NSData *data = nil;
UIImage * image = nil;
if ([string isKindOfClass:[UIImage class]]){
UIImage * image = (UIImage *)string;
data = UIImagePNGRepresentation(image);
} else if ([string isKindOfClass:[NSString class]]) {
NSString *url = (NSString *)string;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1.5];
NSURLResponse *response = nil;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
//如果远程的图片下载不下来,则使用默认图
if (data == nil) {
image = [UIImage imageNamed:@"share_smallProgram"];
data = UIImagePNGRepresentation(image);
}
}
return data;
}
- (SendMessageToWXReq *)requestWithText:(NSString *)text
OrMediaMessage:(WXMediaMessage *)message
bText:(BOOL)bText
......@@ -620,8 +513,8 @@
NSMutableArray *mediaUrl = [NSMutableArray array];
NSURL *videoUrl = [NSURL new];
if ([parameters.allKeys containsObject:@"videoUrl"]) {
videoUrl= parameters[@"videoUrl"];
if ([parameters.allKeys containsObject:ShareVideoUrl]) {
videoUrl= parameters[ShareVideoUrl];
}
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:videoUrl];
......
......@@ -5,7 +5,7 @@
// Created by licong on 2017/8/18.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import "GMShareConstant.h"
#import "NSMutableDictionary+GMShareSDK.h"
#import <WechatOpenSDK/WXApiObject.h>
......@@ -16,11 +16,11 @@
url:(NSURL *)url
title:(NSString *)title
type:(GMShareContentType)type{
self[@"text"] = text;
self[@"images"] = images;
self[@"url"] = url;
self[@"title"] = title;
self[@"type"] = @(type);
self[ShareText] = text;
self[ShareImage] = images;
self[ShareUrl] = url;
self[ShareTitle] = title;
self[ShareContentType] = @(type);
}
- (void)shareSetupShareParamsByText:(NSString *)text
......@@ -29,12 +29,12 @@
title:(NSString *)title
videoUrl:(NSURL *)videoUrl
type:(GMShareContentType)type {
self[@"text"] = text;
self[@"images"] = images;
self[@"url"] = url;
self[@"title"] = title;
self[@"type"] = @(type);
self[@"videoUrl"] = videoUrl;
self[ShareText] = text;
self[ShareImage] = images;
self[ShareUrl] = url;
self[ShareTitle] = title;
self[ShareContentType] = @(type);
self[ShareVideoUrl] = videoUrl;
}
- (void)shareSetupMiniProgramShareParamsByUrl:(NSString *)url
......@@ -44,14 +44,14 @@
description:(NSString *)description
thumbImage:(id)thumbImage
hdImageData:(id)hdImageData{
self[@"url"] = url;
self[@"userName"] = userName;
self[@"path"] = path;
self[@"title"] = title;
self[@"description"] = description;
self[@"thumbImage"] = thumbImage;
self[@"hdImageData"] = hdImageData;
self[@"type"] = @(GMShareContentTypeMiniProgram);
self[ShareUrl] = url;
self[ShareUserName] = userName;
self[SharePath] = path;
self[ShareTitle] = title;
self[ShareDescription] = description;
self[ShareThumbImage] = thumbImage;
self[ShareHdImageData] = hdImageData;
self[ShareContentType] = @(GMShareContentTypeMiniProgram);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment