shareSDK(分享第三方库)的 使用

ShareSDK_v2.4.0新浪登录分享例子:http://pan.baidu.com/share/link?shareid=1290609085&uk=3189484501

这个例子我自己裁剪的官方的例子很好,但代码太多不方便看,其实会一个其他的也就会了。



首先,下载第三方库,可以去官网下载,官网的地址我忘记了,但下面有一个我之前下的和我写的例子,其实官方的例子也写我们只是告诉大家用时需要把哪些代码复制出来就可以用了。


1、导入如下框架和第三方库



新浪微博分享例子下载:http://vdisk.weibo.com/s/BDn59yfnBUifA

下面是微博分享的代码里子:

-(IBAction)shareSina:(id)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:@"fenxiang"
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:@"f"]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeSinaWeibo
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

这些代码例子可以在官方提供的例子中找到,官方例子下载地址: http://vdisk.weibo.com/s/BDn59yfnBUiAb
都在AGApiViewController.m这个类中,大家找到这类就可以在里面找到对应的方法。
/**
 *	@brief	分享到新浪微博
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToSinaWeiboClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeSinaWeibo
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];    
}

/**
 *	@brief	分享到腾讯微博
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToTencentWeiboClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeTencentWeibo
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享给QQ好友
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToQQFriendClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText
                                                              title:@"ShareSDK"
                                                                url:@"http://www.sharesdk.cn"
                                                       musicFileUrl:nil
                                                            extInfo:nil
                                                           fileData:nil];
    [ShareSDK shareContentWithType:ShareTypeQQ
                           content:publishContent
               containerController:self
                     statusBarTips:NO
                   oneKeyShareList:nil
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到QQ空间
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToQQSpaceClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [publishContent addQQSpaceUnitWithTitle:@"Hello QQ空间"
                                        url:@"http://www.sharesdk.cn"
                                    comment:INHERIT_VALUE
                                    summary:CONTENT
                                      image:INHERIT_VALUE
                               imageQuality:INHERIT_VALUE
                                       type:INHERIT_VALUE
                                    playUrl:nil
                                  syncWeibo:nil];
    
    [ShareSDK shareContentWithType:ShareTypeQQSpace
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享给微信好友
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToWeixinSessionClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText
                                                              title:@"ShareSDK"
                                                                url:@"http://www.sharesdk.cn"
                                                       musicFileUrl:nil
                                                            extInfo:nil
                                                           fileData:nil];
    [ShareSDK shareContentWithType:ShareTypeWeixiSession
                           content:publishContent
               containerController:self
                     statusBarTips:NO
                   oneKeyShareList:nil
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享给微信朋友圈
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToWeixinTimelineClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeNews
                                                              title:@"ShareSDK"
                                                                url:@"http://www.baidu.com"
                                                       musicFileUrl:nil
                                                            extInfo:nil
                                                           fileData:nil];
    [ShareSDK shareContentWithType:ShareTypeWeixiTimeline
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                          autoAuth:YES
                        convertUrl:YES
                  shareViewOptions:nil
                            result:nil];
}

/**
 *	@brief	分享到网易微博
 *
 *	@param 	sender 	事件对象
 */
- (void)shareTo163WeiboClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareType163Weibo
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到搜狐微博
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToSohuWeiboClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeSohuWeibo
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到人人网
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToRenRenClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    
    [ShareSDK shareContentWithType:ShareTypeRenren
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到开心网
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToKaiXinClickHandler:(UIButton *)sender
{
    
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeKaixin
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到豆瓣我说
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToDouBanClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeDouBan
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到Instapaper
 *
 *	@param 	sender 	事件对象
 */
- (void)shareToInstapaperClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeInstapaper
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到Facebook
 *
 *	@param 	sender  事件对象
 */
- (void)shareToFacebookClickHandler:(UIButton *)sender

{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    
    [ShareSDK shareContentWithType:ShareTypeFacebook
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	分享到Twitter
 *
 *	@param 	sender 	Twitter
 */
- (void)shareToTwitterClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    
    [ShareSDK shareContentWithType:ShareTypeTwitter
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:nil];
}

/**
 *	@brief	短信分享
 *
 *	@param 	sender 	事件对象
 */
- (void)shareBySMSClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeSMS
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:^(ShareType type, SSPublishContentState state, id<ISSStatusInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                if (state == SSPublishContentStateSuccess)
                                {
                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                                        message:@"分享成功"
                                                                                       delegate:nil
                                                                              cancelButtonTitle:@"知道了"
                                                                              otherButtonTitles: nil];
                                    [alertView show];
                                    [alertView release];
                                }
                                else if(state == SSPublishContentStateFail)
                                {
                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                                        message:error.errorDescription
                                                                                       delegate:nil
                                                                              cancelButtonTitle:@"知道了"
                                                                              otherButtonTitles: nil];
                                    [alertView show];
                                    [alertView release];
                                }
                            }];
}

/**
 *	@brief	邮件分享
 *
 *	@param 	sender 	事件对象
 */
- (void)shareByMailClickHandler:(UIButton *)sender
{
    id<ISSPublishContent> publishContent = [ShareSDK publishContent:CONTENT
                                                     defaultContent:@""
                                                              image:[UIImage imageNamed:IMAGE_NAME]
                                                       imageQuality:0.8
                                                          mediaType:SSPublishContentMediaTypeText];
    [ShareSDK shareContentWithType:ShareTypeMail
                           content:publishContent
               containerController:self
                     statusBarTips:YES
                   oneKeyShareList:[NSArray defaultOneKeyShareList]
                    shareViewStyle:ShareViewStyleDefault
                    shareViewTitle:@"内容分享"
                            result:^(ShareType type, SSPublishContentState state, id<ISSStatusInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                if (state == SSPublishContentStateSuccess)
                                {
                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                                        message:@"分享成功"
                                                                                       delegate:nil
                                                                              cancelButtonTitle:@"知道了"
                                                                              otherButtonTitles: nil];
                                    [alertView show];
                                    [alertView release];
                                }
                                else if(state == SSPublishContentStateFail)
                                {
                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                                        message:error.errorDescription
                                                                                       delegate:nil
                                                                              cancelButtonTitle:@"知道了"
                                                                              otherButtonTitles: nil];
                                    [alertView show];
                                    [alertView release];
                                }
                            }];
}



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
在Unity Web端使用ShareSDK实现分享功能,需要进行以下步骤: 1.下载ShareSDK的Web端SDK 你需要从ShareSDK官网下载Web端SDK,并解压到你的工程目录中。 2.添加ShareSDK的依赖 在你的Unity Web项目中,需要添加ShareSDK的依赖。你可以通过以下方式来添加依赖: - 在你的HTML文件中添加以下代码: ```html <script src="path/to/ShareSDK.min.js"></script> ``` - 或者在你的Unity脚本中使用以下代码: ```csharp using UnityEngine; using System.Collections; public class ShareSDKManager : MonoBehaviour { void Start () { // 加载ShareSDK的依赖 Application.ExternalEval("var script = document.createElement('script');" + "script.type = 'text/javascript';" + "script.src = 'path/to/ShareSDK.min.js';" + "document.getElementsByTagName('head')[0].appendChild(script);"); } } ``` 3.初始化ShareSDK 在你的Unity脚本中,需要初始化ShareSDK。你可以使用以下代码来初始化: ```csharp using UnityEngine; using System.Collections; using cn.sharesdk.unity3d; public class ShareSDKManager : MonoBehaviour { public ShareSDK shareSDK; void Start () { // 初始化ShareSDK shareSDK = GetComponent<ShareSDK>(); shareSDK.InitSDK("YourAppKey", "YourAppSecret"); } } ``` 4.调用ShareSDK分享接口 在你的Unity脚本中,你可以调用ShareSDK分享接口来实现分享功能。以下是示例代码: ```csharp using UnityEngine; using System.Collections; using cn.sharesdk.unity3d; public class ShareSDKManager : MonoBehaviour { public ShareSDK shareSDK; void Start () { // 初始化ShareSDK shareSDK = GetComponent<ShareSDK>(); shareSDK.InitSDK("YourAppKey", "YourAppSecret"); } // 分享到Facebook public void ShareToFacebook() { ShareContent content = new ShareContent(); content.SetText("ShareSDK is awesome!"); content.SetUrl("http://www.mob.com"); content.SetTitle("ShareSDK Title"); content.SetShareType(ContentType.Webpage); content.SetImageUrl("http://www.mob.com/assets/images/ShareSDK_pic_1-09d2933e.png"); shareSDK.ShareContent(PlatformType.Facebook, content); } } ``` 以上代码中,我们调用了ShareSDKShareContent方法,并传入了分享的内容和分享的平台类型。你可以根据需要修改分享的内容和平台类型。 注意:在调用ShareSDK分享接口之前,需要确保用户已经登录到相应的社交媒体平台,并且对应的API和SDK已经正确配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杜甲同学

感谢打赏,我会继续努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值