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

来源:互联网 发布:林书豪各赛季数据 编辑:程序博客网 时间:2024/05/07 03:37

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


接下来我们将演示如何将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
原创粉丝点击