码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 自定义分享功能(分享到微博等sahreSDK)

时间:2015-07-01 18:27:57      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:ios   sharesdk   分享到微博等   自定义分享内容   

本次教程是参照官方的shareSDK进行操作(按照教程进行前期的准备操作,该导入的导入,该添加的添加)

做完前期准备工作然后进行下面的操作

首先要对需求的分享方式进行声明

 /**
     *  分享方式的声明引用
     */
    [ShareSDK registerApp:@"3df7a36158b2"];
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                             redirectUri:@"http://www.sharesdk.cn"];

选择分享的途径以及制定分享的内容

//选择分享的途径
switch (sender.tag) {
            
        case 11:
            type = ShareTypeYiXinSession;
            break;
        case 12:
            type = ShareTypeYiXinTimeline;
            break;
        case 13:
            type = ShareTypeWeixiSession;
            break;
        case 14:
            type = ShareTypeWeixiTimeline ;
            break;
        case 15:
            type = ShareTypeSinaWeibo;
            break;
        case 16:
            type = ShareTypeQQ ;
            break;
        case 17:
            type =  ShareTypeQQSpace;
            break;
        case 18:
            type = ShareTypeRenren;
            break;
        case 19:
            type = ShareTypeSMS;
            break;
        case 20:
            type = ShareType163Weibo;
            break;
        case 21:
            type = ShareTypeTencentWeibo;
            break;
        case 22:
            type = ShareTypeEvernote;
            break;
        case 23:
            type = ShareTypeInstapaper;
            break;
        case 24:
            type = ShareTypeMail;
            break;
        case 25:
            type = ShareTypeYouDaoNote;
            break;
        case 26:
            type = ShareTypePocket;
            break;
            
        default:
            break;
    }
//分享内容等参数的制定
 id<ISSContent> publishContent = [ShareSDK content:userWriteTextView.text defaultContent:nil image:[ShareSDK pngImageWithImage:shareImage] title:@"This is title" url:@"http://mob.com" description:@"This is description" mediaType:SSPublishContentMediaTypeNews];
        //2.分享
    [ShareSDK shareContent:publishContent  type:type  authOptions:nil  shareOptions:nil  statusBarTips:YES
                    result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
             if (state == SSPublishContentStateSuccess){
                  NSLog(@"分享成功");
                  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"分享成功" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                  [alert show];
              } else if (state == SSPublishContentStateFail){
                  NSLog(@"分享失败,错误码:%ld,错误描述%@",(long)[error errorCode],[error errorDescription]);
                  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"分享失败,请看日记错误描述" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                  [alert show];
              }
          }];
}

下面的这个方法是判断用户是否登录的

</pre><pre name="code" class="objc"> id<ISSPlatformCredential> credential = [ShareSDK getCredentialWithType:ShareTypeSinaWeibo];
    if(credential!=nil&&[credential available]){
         NSLog(@"处在登录状态!");
    }else {
         NSLog(@"未处在登录状态!");
    }





iOS 自定义分享功能(分享到微博等sahreSDK)

标签:ios   sharesdk   分享到微博等   自定义分享内容   

原文地址:http://blog.csdn.net/red_coraldown/article/details/46711151

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!