使用shareSDK调用sina微博客户端,从客户端直接分享

示例:

   使用shareSDK调用sina微博客户端,从客户端直接分享_第1张图片 


使用shareSDK调用sina微博客户端,从客户端直接分享_第2张图片


#import "AppDelegate.h"
#import <ShareSDK/ShareSDK.h>
#import "WeiboSDK.h"


@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //1.初始化ShareSDK应用,字符串"iosv1101"是应该换成你申请的ShareSDK应用中的Appkey
    [ShareSDK registerApp:@"567ca5dce0da"];
    
    //2. 初始化社交平台
    //2.1 代码初始化社交平台的方法
    [self initializePlat];
    
    //2.2 使用后台管理初始社交平台的方法
    //    [self initializePlatForTrusteeship];
    
    //3.设置根视图控制器,如果没有使用storyboard一定要设置。
    

    
    return YES;
}

- (BOOL)application:(UIApplication *)application
      handleOpenURL:(NSURL *)url
{
   return [ShareSDK handleOpenURL:url  wxDelegate:self];
    
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                 sourceApplication:sourceApplication
                        annotation:annotation
                        wxDelegate:self];
    
   
}



- (void)initializePlat
{
    /**
     连接新浪微博开放平台应用以使用相关功能,此应用需要引用SinaWeiboConnection.framework
     http://open.weibo.com上注册新浪微博开放平台应用,并将相关信息填写到以下字段
     **/
    <span style="color:#ff0000;">[ShareSDK connectSinaWeiboWithAppKey:@"220713449"
                               appSecret:@"0ced62ad68f3fbbf2d00e41f2ba1e99e"
                             redirectUri:@"http://www.baidu.com"
                            weiboSDKCls:[WeiboSDK class]];</span>
   
}


点击分享事件:

- (IBAction)share:(id)sender
{
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"image01" ofType:@"jpg"];
    
    //1、构造分享内容
    id<ISSContent> publishContent = [ShareSDK content:@"要分享的内容"
                                       defaultContent:@"默认内容"
                                                image:[ShareSDK imageWithPath:imagePath]
                                                title:@"ShareSDK"
                                                  url:@"http://www.mob.com"
                                          description:@"这是一条演示信息"
                                            mediaType:SSPublishContentMediaTypeNews];
    



    <span style="color:#ff0000;">[ShareSDK clientShareContent:publishContent //内容对象
                                                      type:ShareTypeSinaWeibo //平台类型
                                             statusBarTips:YES
                                                    result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {//返回事件
                                                        
                                                        if (state == SSPublishContentStateSuccess)
                                                        {
                                                            NSLog(NSLocalizedString(@"TEXT_SHARE_SUC", @"分享成功!"));
                                                        }
                                                        else if (state == SSPublishContentStateFail)
                                                        {
                                                            NSLog(NSLocalizedString(@"TEXT_SHARE_FAI", @"分享失败!"), [error errorCode], [error errorDescription]);
                                                        }
                                                    }];</span>
    
}





你可能感兴趣的:(使用shareSDK调用sina微博客户端,从客户端直接分享)