zoukankan      html  css  js  c++  java
  • iOS-ShareSDK的使用(转)

    官方下载ShareSDK iOS:http://sharesdk.cn/

    ShareSDK社会化分享

    包含“社会化分享组件”“社会化登录组件”“第三方评论和赞”三大模块,并有详尽的数据统计后台,助力移动开发者接入第三方平台实现快速成长。

    ShareSDK产品介绍

    ShareSDK是为iOS、Android的App提供社会化功能的一个组件,开发者仅需10分钟即可集成到自己的 App中,它不仅支持国内外40多家的主流社交平台,帮助开发者轻松实现社会化分享、登录、关注、获得用户资料、获取好友列表等主流的社会化功能,还有强 大的社会化统计分析管理后台,可以实时了解用户、信息流、回流率、传播效率等数据,有效地指导移动App的日常运营与推广,同时为App引入更多的社会化 流量。

    为什么使用ShareSDK?

    快速获取更多用户

    更流畅的体验 ShareSDK统一了所有的社交平台的接口,并拥有完善的开发文档;

    更高效的推广

    ShareSDK七大优势

    永久免费

    自定义UI

    一键分享

    支持平台最全

    SDK体积最小

    数据统计最全

    深度支持游戏:

    • 好友关系运用——邀请好友、求助、发起挑战、索取道具、好友排行、分享炫耀。

    ShareSDK功能介绍

    1 一键分享

    支持分享文字、图片、图文、音乐、视频、链接,可一键分享至微信、微博、Facebook、Twitter等多个平台;支持@好友和话题功能。轻松实现你分享出去的链接中,仅让用户看到您的官网地址,而并非ShareSDK。

     

    2 第三方登录

    利用第三方社交网络账号QQ、微博等方式登录APP更方便快捷,用户授权后,开发者也可方便获取用户基本信息,如头像、昵称和签名。可轻松实现获取微博好友关系、微博内容、用户资料、LBS信息。

    3 评论和赞

    用户可通过第三方账号或者自有账号登录,对你设置的主题进行评论或赞,同时您也能在后台审核评论内容,轻松建立社区氛围。

    4 给你一个看得见用户分享行为的水晶球——社会化数据统计

    ShareSDK统计后台实时查看App各项社会化数据,帮助开发者了解社会化数据的各项指标,便于开发者从社交属性、用户分布、平台选择、营销效果等多个维度评估App,助力产品优化改进。

    Share SDK的集成:

    前提:在友盟官网注册应用得到appkey (获取AppKey)

    如何在我们的官网注册应用得到appkey,请点击链接看里面的操作步骤

    (1)官方下载ShareSDK iOS,地址:http://sharesdk.cn/

    (2)根据实际情况,引入相关的库,参考官方集成文档。

    (3)在项目的AppDelegate中一般情况下有三个操作,第一是注册ShareSDK,第二是注册各个平台的账号,第三是关于微信等应用的回调处理。

    在appdelegate.m中:

     // 分享
        [DMShare registerApp];
        [DMShare addSharePlat];

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

    定义一个类继承nsobject:

    #import <Foundation/Foundation.h>
    #import <ShareSDK/ShareSDK.h>
    #import <TencentOpenAPI/QQApiInterface.h>
    #import <TencentOpenAPI/TencentOAuth.h>
    #import "WXApi.h"
    #import "WeiboSDK.h"
    #import "DMShareModel.h"

    @interface DMShare : NSObject

    + (void)registerApp;
    + (void)addSharePlat;
    + (void)showShare:(DMShareModel *)shareModel addTarget:(id)target;


    #import "DMShare.h"

    @interface DMShare () <ISSShareViewDelegate>

    @end

    @implementation DMShare

    + (void)registerApp
    {
        [ShareSDK registerApp:@"a63d9d1a2908"];
    }

    + (void)addSharePlat
    {
        //添加新浪微博应用
    //    [ShareSDK connectSinaWeiboWithAppKey:@"199632105"
    //                               appSecret:@"526a34cbb19d70f685a1dc25d2e09c76"
    //                             redirectUri:@"https://api.weibo.com/oauth2/default.html"];
        
        //添加QQ空间应用
    //    [ShareSDK connectQZoneWithAppKey:@"1104479433"
    //                           appSecret:@"safjx8rydezdBCZC"
    //                   qqApiInterfaceCls:[QQApiInterface class]
    //                     tencentOAuthCls:[TencentOAuth class]];
        
        //添加QQ应用
    //    [ShareSDK connectQQWithQZoneAppKey:@"1104479433"
    //                     qqApiInterfaceCls:[QQApiInterface class]
    //                       tencentOAuthCls:[TencentOAuth class]];
        
        //添加微信应用
        [ShareSDK connectWeChatWithAppId:@"wx90b632077a12a1be"
                               appSecret:@"2ba12ff131ca59db383c49cf2ec59e1e"
                               wechatCls:[WXApi class]];
    }

    + (void)showShare:(DMShareModel *)shareModel addTarget:(id)target
    {
        NSArray *shareList = [ShareSDK getShareListWithType:ShareTypeWeixiSession, ShareTypeWeixiTimeline,nil];
        id<ISSAuthOptions> authOptions = [ShareSDK authOptionsWithAutoAuth:YES
                                                             allowCallback:NO
                                                             authViewStyle:SSAuthViewStyleFullScreenPopup
                                                              viewDelegate:target
                                                   authManagerViewDelegate:target];
        //隐藏logo
        [authOptions setPowerByHidden:YES];
        
    //    id<ISSShareOptions> shareOptions = [ShareSDK defaultShareOptionsWithTitle:@"内容分享"
    //                                                              oneKeyShareList:[NSArray defaultOneKeyShareList]
    //                                                               qqButtonHidden:YES
    //                                                        wxSessionButtonHidden:YES
    //                                                       wxTimelineButtonHidden:YES
    //                                                         showKeyboardOnAppear:NO
    //                                                            shareViewDelegate:target
    //                                                          friendsViewDelegate:target
    //                                                        picViewerViewDelegate:nil];
        id<ISSShareOptions> shareOptions = [ShareSDK defaultShareOptionsWithTitle:@"内容分享"
                                                                  oneKeyShareList:shareList
                                                                   qqButtonHidden:YES
                                                            wxSessionButtonHidden:YES
                                                           wxTimelineButtonHidden:YES
                                                             showKeyboardOnAppear:NO
                                                                shareViewDelegate:target
                                                              friendsViewDelegate:target
                                                            picViewerViewDelegate:nil];
        
        //在授权页面中添加关注官方微博
    //    [authOptions setFollowAccounts:[NSDictionary dictionaryWithObjectsAndKeys:
    //                                    [ShareSDK userFieldWithType:SSUserFieldTypeName value:@"ShareSDK"],
    //                                    SHARE_TYPE_NUMBER(ShareTypeSinaWeibo),
    //                                    [ShareSDK userFieldWithType:SSUserFieldTypeName value:@"ShareSDK"],
    //                                    SHARE_TYPE_NUMBER(ShareTypeTencentWeibo),
    //                                    nil]];
        
        //构造分享内容
        id<ISSContent> publishContent = [ShareSDK content:shareModel.content
                                           defaultContent:shareModel.defaultContent
                                                    image:[ShareSDK imageWithPath:shareModel.imageUrl]
                                                    title:shareModel.title
                                                      url:shareModel.url
                                              description:shareModel.content
                                                mediaType:SSPublishContentMediaTypeNews];
        //定制QQ空间信息
    //    [publishContent addQQSpaceUnitWithTitle:shareModel.title
    //                                        url:shareModel.url
    //                                       site:nil
    //                                    fromUrl:nil
    //                                    comment:[SSInheritValue inherit]
    //                                    summary:[SSInheritValue inherit]
    //                                      image:[SSInheritValue inherit]
    //                                       type:[SSInheritValue inherit]
    //                                    playUrl:nil
    //                                       nswb:nil];
        
        //定制QQ分享信息
    //    [publishContent addQQUnitWithType: INHERIT_VALUE
    //                              content: shareModel.content
    //                                title: shareModel.title
    //                                  url: shareModel.url
    //                                image:[ShareSDK imageWithPath:shareModel.imageUrl]];
        
        //定制微信好友信息
        [publishContent addWeixinSessionUnitWithType: INHERIT_VALUE
                                             content: INHERIT_VALUE
                                               title: shareModel.title
                                                 url: shareModel.url
                                          thumbImage: [ShareSDK imageWithPath:shareModel.imageUrl]
                                               image: INHERIT_VALUE
                                        musicFileUrl: nil
                                             extInfo: nil
                                            fileData: nil
                                        emoticonData: nil];
        
        //定制微信朋友圈信息
        [publishContent addWeixinTimelineUnitWithType: [NSNumber numberWithInteger:SSPublishContentMediaTypeNews]
                                              content: INHERIT_VALUE
                                                title: shareModel.title
                                                  url: shareModel.url
                                           thumbImage: [ShareSDK imageWithPath:shareModel.imageUrl]
                                                image: INHERIT_VALUE
                                         musicFileUrl: nil
                                              extInfo: nil
                                             fileData: nil
                                         emoticonData: nil];

        
        //定制微信收藏信息
    //    [publishContent addWeixinFavUnitWithType: INHERIT_VALUE
    //                                     content: INHERIT_VALUE
    //                                       title: shareModel.title
    //                                         url: shareModel.url
    //                                  thumbImage: [ShareSDK imageWithPath:shareModel.imageUrl]
    //                                       image: INHERIT_VALUE
    //                                musicFileUrl: nil
    //                                     extInfo: nil
    //                                    fileData: nil
    //                                emoticonData: nil];
        
        
        [ShareSDK showShareActionSheet: nil
                             shareList: shareList
                               content: publishContent
                         statusBarTips: YES
                           authOptions: authOptions
                          shareOptions: shareOptions
                                result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                    if (state == SSResponseStateSuccess) {
                                        NSLog(@"分享成功");
                                    } else if (state == SSResponseStateFail) {
                                        NSLog(@"分享失败,错误码:%d,错误描述:%@", [error errorCode], [error errorDescription]);
                                    }
                                }];
        
        [ShareSDK cancelAuthWithType:ShareTypeSinaWeibo];
    }

    #####分享按钮的触摸事件

    #pragma mark - 分享请求
    - (void)shareRequestWithParameters:(NSDictionary *)parameters WithButton:(UIButton*)sender
    {
        [DMHttpRequest get:DMShareUrl parameters:parameters success:^(id responseObj) {
            DMRequestCode code = [DMTools responseCode:responseObj];
            sender.userInteractionEnabled = YES;
            NSLog(@"%@",responseObj);
            switch (code) {
                case DMRequestSuccess: {
                    [self.hud hide:YES];
                    //                [DMTools loadSuccessHUD:self.hud text:[DMTools responseMessage:responseObj] delay:DMHUDDelayTimeInterval];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (responseObj[@"data"]==nil||[responseObj[@"data"]isKindOfClass:[NSNull class]]) {
                            return ;
                        }
                        // 请求完成后加载数据
                        DMShareModel *model = [[DMShareModel alloc]init];
                        model.title = responseObj[@"data"][@"title"];
                        model.content = responseObj[@"data"][@"content"];
                        if ([responseObj[@"data"][@"pic_url"] hasPrefix:@"http"]) {
                            model.imageUrl =  [ShareSDK imageWithUrl:responseObj[@"data"][@"pic_url"]];
                        }else
                        {
                            model.imageUrl = [ShareSDK imageWithPath:[[NSBundle mainBundle] pathForResource:@"icon_钱富宝logo_登录页@3x" ofType:@"png"]] ;
                        }
                        model.url = responseObj[@"data"][@"url"];
                        self.shareModel = model;
                        [[DMShareView shareInstance]showShare:self.shareModel addTarget:self];
                        //                    [DMShare showShare:self.shareModel addTarget:self];
                        
                    });
                    break;
                }
                default:
                    //                [DMTools loadFailedHUD:self.hud text:[DMTools responseMessage:responseObj] delay:DMHUDDelayTimeInterval];
                {
                    [self.hud hide:YES];
                    [[DMShareView shareInstance]showShare:nil addTarget:self];
                    
                    break;
                }
            }
            
        } failure:^(NSError *error) {
            [self.hud hide:YES];
            //        [DMTools loadFailedHUD:self.hud text:DMRequestFailureNote delay:DMHUDDelayTimeInterval];
            [[DMShareView shareInstance]showShare:nil addTarget:self];
            sender.userInteractionEnabled = YES;
        }];
    }

  • 相关阅读:
    JavaEE——SpringMVC(11)--拦截器
    JavaEE——SpringMVC(10)--文件上传 CommonsMultipartResovler
    codeforces 460A Vasya and Socks 解题报告
    hdu 1541 Stars 解题报告
    hdu 1166 敌兵布阵 解题报告
    poj 2771 Guardian of Decency 解题报告
    hdu 1514 Free Candies 解题报告
    poj 3020 Antenna Placement 解题报告
    BestCoder5 1001 Poor Hanamichi(hdu 4956) 解题报告
    poj 1325 Machine Schedule 解题报告
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5381976.html
Copyright © 2011-2022 走看看