05.集成ShareSDK社会化分享组件

在我的界面中,有个分享软件选项,点击它将会弹出如图所示分享界面。


接下来我们将演示如何将ShareSDK集成到我们的APP中。

1.首先,注册开发者帐号:http://www.mob.com/#/reg

2.下载ShareSDK:http://www.mob.com/#/downloadDetail/ShareSDK/ios


3.集成指南:http://wiki.mob.com/快速集成指南/

4.完成以后将会是这样:



在AppDelegate.m文件里:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self initShareSDK];
return YES;
}
/**
 *  初始化shareSDK
 */
- (void)initShareSDK
{
    [ShareSDK registerApp:@"appKey"];
    
    //添加新浪微博应用
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                             redirectUri:@"http://www.sharesdk.cn"];
    //微信登陆的时候需要初始化
    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
                           appSecret:@"64020361b8ec4c99936c0e3999a9f249"
                           wechatCls:[WXApi class]];
    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"100371282"
                           appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    //添加QQ应用  注册网址   http://mobile.qq.com/api/
    [ShareSDK connectQQWithQZoneAppKey:@"100371282"
                     qqApiInterfaceCls:[QQApiInterface class]
                       tencentOAuthCls:[TencentOAuth class]];
}
到此,ShareSDK初始化完毕。接下来就是调用了:点击< 分享软件>,调用该函数

- (void)shareApp
{
    NSArray *shareList = [ShareSDK getShareListWithType:
                          ShareTypeSinaWeibo,
                          ShareTypeWeixiSession,
                          ShareTypeQQ,
                          ShareTypeWeixiTimeline,
                          ShareTypeWeixiFav,
                          ShareTypeQQSpace,nil];
    //构造分享内容
    NSString *url = @"https://itunes.apple.com/cn/app/wu-liu-tang-shan/id990902550?mt=8";
    id<ISSContent> publishContent = [ShareSDK content:url
                                       defaultContent:@"share"
                                                image:nil
                                                title:@"Share"
                                                  url:url
                                          description:@"share"
                                            mediaType:SSPublishContentMediaTypeNews];
    //创建弹出菜单容器
    id<ISSContainer> container = [ShareSDK container];
    [container setIPadContainerWithView:self.view arrowDirect:UIPopoverArrowDirectionUp];
    
    //弹出分享菜单
    [ShareSDK showShareActionSheet:container
                         shareList:shareList
                           content:publishContent
                     statusBarTips:YES
                       authOptions:nil
                      shareOptions:nil
                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end)
    {
    if (state == SSResponseStateSuccess)
    {
        [MBProgressHUD showSuccess:@"分享成功"];
    }
    else if (state == SSResponseStateFail)
    {
        NSString *msg = [NSString stringWithFormat:@"错误码:%ld,错误描述:%@", [error errorCode], [error errorDescription]];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
    }}];
}

我们可以分享软件的App Store链接了。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值