版本記錄
版本號 | 時間 |
---|---|
V1.0 | 2017.08.03 |
前言
前面我寫過
ShareSDK
登錄困肩,以及蘋果原生的幾種分享方式,但是還沒有對ShareSDK
在分享上的應(yīng)用進(jìn)行配置静浴,這一篇主要就是講解ShareSDK
在分享上的應(yīng)用击儡。
功能要求
結(jié)合工程實踐术奖,演示ShareSDK
在分享上的應(yīng)用站楚。
功能實現(xiàn)
下面我就結(jié)合具體的工程實踐脱惰,詳細(xì)的講解下ShareSDK
的分享實現(xiàn)。
1. 工程配置
首先我們需要配置下工程窿春。
工程配置請參考我寫的ShareSDK
登錄篇拉一。
2. 代碼實現(xiàn)
下面寫一個分享的工具類實現(xiàn)第三方平臺的分享,直接看代碼吧旧乞。
1. JJShareTool.h
#import <Foundation/Foundation.h>
@interface JJShareTool : NSObject
//分享
+ (void)shareWithButtonTag:(NSInteger)btnTag Text:(NSString *)text
images:(id)images
url:(NSURL *)url
title:(NSString *)title
success:(void(^)(BOOL isSuccess,NSString* channelType))success
fail:(void(^)(BOOL isFail))fail
cancel:(void(^)(BOOL isCancel))cancel
notInstalled:(void(^)(BOOL isInstalled, NSString *msg))notInstalled;
@end
2. JJShareTool.m
#import "JJShareTool.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKExtension/SSEShareHelper.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>
#import <ShareSDKUI/SSUIShareActionSheetCustomItem.h>
#import <ShareSDK/ShareSDK+Base.h>
#import <ShareSDKExtension/ShareSDK+Extension.h>
#import "WXApi.h"
#import "WeiboSDK.h"
//騰訊開放平臺(對應(yīng)QQ和QQ空間)SDK頭文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
@implementation JJShareTool
//分享
+ (void)shareWithButtonTag:(NSInteger)btnTag Text:(NSString *)text
images:(id)images
url:(NSURL *)url
title:(NSString *)title
success:(void(^)(BOOL isSuccess,NSString* channelType))success
fail:(void(^)(BOOL isFail))fail
cancel:(void(^)(BOOL isCancel))cancel
notInstalled:(void(^)(BOOL isInstalled, NSString *msg))notInstalled
{
if (btnTag == 5) {
if (notInstalled) {
if (![WeiboSDK isWeiboAppInstalled]) {
notInstalled([WeiboSDK isWeiboAppInstalled], @"未安裝微博客戶端蔚润,請安裝后重新分享");
return;
}
}
} else if (btnTag%2==1) {
if (notInstalled) {
if (![WXApi isWXAppInstalled]) {
notInstalled([WXApi isWXAppInstalled], @"未安裝微信客戶端,請安裝后重新分享");
return;
}
}
} else {
if (notInstalled) {
if (![QQApiInterface isQQInstalled]) {
notInstalled([QQApiInterface isQQInstalled], @"未安裝QQ客戶端尺栖,請安裝后重新分享");
return;
}
}
}
SSDKPlatformType platformType =[[self class] getPlatformTypeWithButtonTag:btnTag];
int SSDKContentType =SSDKContentTypeAuto;
if (platformType ==SSDKPlatformTypeSinaWeibo) {
SSDKContentType = SSDKContentTypeWebPage;
}
if (platformType == SSDKPlatformSubTypeWechatTimeline) {
title = text;
}
if (!title || title.length == 0) {
title = @"XXXXX";
}
NSInteger channelType =[[self class] getChannelTypeWithButtonTag:btnTag];
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:text images:images url:url title:title type:SSDKContentType];
[[self class] shareWithShareParams:shareParams platformType:platformType channelType:channelType success:success fail:fail cancel:cancel];
}
+ (SSDKPlatformType)getPlatformTypeWithButtonTag:(NSInteger)btnTag
{
SSDKPlatformType platformType;
switch (btnTag) {
case 5:
//新浪
platformType = SSDKPlatformTypeSinaWeibo;
break;
case 1:
//微信
platformType = SSDKPlatformSubTypeWechatSession;
break;
case 3:
//朋友圈
platformType = SSDKPlatformSubTypeWechatTimeline;
break;
case 2:
//qq
platformType = SSDKPlatformSubTypeQQFriend;
break;
case 4:
//qq空間
// [[self class] chekoutQQAppInstalled];
platformType = SSDKPlatformSubTypeQZone;
break;
default:
platformType = SSDKPlatformSubTypeWechatTimeline;
break;
}
return platformType;
}
+ (NSInteger)getChannelTypeWithButtonTag:(NSInteger)btnTag
{
NSInteger channelType = 0;
switch (btnTag) {
case 5:
//新浪
channelType = 2;
break;
case 1:
//微信
channelType = 3;
break;
case 3:
//朋友圈
channelType = 4;
break;
case 2:
//qq
channelType = 1;
break;
case 4:
//qq空間
channelType = 5;
break;
default:
break;
}
return channelType;
}
+ (void)shareWithShareParams:(NSMutableDictionary *)shareParams platformType:(SSDKPlatformType)platformType channelType:(NSInteger)channelType success:(void(^)(BOOL isSuccess,NSString * channelType))success
fail:(void(^)(BOOL isFail))fail
cancel:(void(^)(BOOL isCancel))cancel
{
//使用客戶端分享
[shareParams SSDKEnableUseClientShare];
//進(jìn)行分享
[ShareSDK share:platformType
parameters:shareParams
onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
switch (state) {
case SSDKResponseStateBegin: {
break;
}
case SSDKResponseStateSuccess: {
if (success) {
success(YES,[NSString stringWithFormat:@"%ld",channelType]);
}
break;
}
case SSDKResponseStateFail: {
if (fail) {
fail(YES);
}
break;
}
case SSDKResponseStateCancel: {
if (cancel) {
cancel(YES);
}
break;
}
}
}];
}
@end
功能效果
下面我們就看幾個分享的效果圖嫡纠。
可見,實現(xiàn)了分享。
后記
分享就到此結(jié)束了除盏,后期還會和分享更多的好玩的叉橱。謝謝大家的支持。