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


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


    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];
                                    }
                                }];
    }
    



  • 相关阅读:
    CJB的大作
    OI省选算法汇总
    bzoj1078【SCOI2008】斜堆
    zrt中文题
    bzoj4726【POI2017】Sabota?
    bzoj4591 【Shoi2015】超能粒子炮·改
    bzoj2086【Poi2010】Blocks
    bzoj2091【Poi2010】The Minima Game
    bzoj2038小z的袜子
    bzoj4282慎二的随机数列
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3285519.html
Copyright © 2020-2023  润新知