Latest 1.0.0
Homepage https://github.com/LiuFuBo1991/LFBSocialSDK
License MIT
Platforms ios 8.0, requires ARC
Dependencies WechatOpenSDK, TencentOpenAPI, WeiboSDK, Masonry
Authors

License MIT 
Cocoapods 
Cocoapods 

LFBSocialSDK是一款第三方分享框架,提供了优雅便捷的调用方式,让你有更多的精力专注其他业务,只需要很少的配置,就可完成分享。

LFBSocialSDK提供了哪些功能?

  • [x] 支持微信、朋友圈、小程序、QQ、QQZone、新浪微博分享,并且后续会持续增加分享平台
  • [x] 支持第三方的登陆功能
  • [x] 支持个人自定义分享视图以及框架分享视图两种UI选择
  • [x] 配置哪些平台,当使用框架展示视图时就展示你配置过的平台
  • [x] 数据配置统一通过model配置,用户根据分享类型选择添加分享参数,项目提供有一份各个平台分享必要参数,用户可通过阅读文档来配置参数 

安装

CocoaPods

1、可以在Podfile中加入下面一行代码来使用LFBSocialSDK

pod ‘LFBSocialSDK’

手动导入

1、下载LFBSocialSDK文件下所有内容并拖入你的工程中

2、导入 ‘LFBSocialSDK.h’

添加项目配置

在Other Linker Flags加入-Objc, 注意不要手动写为-Objc
image

-Objc属于链接必备参数,如果不加此项,会导致库文件无法被正确链接,SDK无法正常运行

加入依赖系统库

在General下的Linked Frameworks and Libraries添加系统库

image

加入以下系统库


libsqlite3.tbd  
CoreGraphics.framework

第三方平台库添加

根据集成的不同平台加入相关的依赖库,未列出平台则不需添加添加方式:选中项目Target -> General -> Linked Frameworks and Libraries列表中进行添加

微信(完整版)

精简版无需添加以下依赖库


SystemConfiguration.framework 
CoreTelephony.framework 
libsqlite3.tbd 
libc++.tbd 
libz.tbd    

QQ(完整版)

精简版无需添加以下依赖库


SystemConfiguration.framework 
libc++.tbd     

新浪微博(精简版)

 
Photos.framework 

新浪微博(完整版)

  
SystemConfiguration.framework 
CoreTelephony.framework 
ImageIO.framework 
libsqlite3.tbd 
libz.tbd  
Photos.framework 

配置SSO白名单

如果你的应用使用了如SSO授权登录或跳转到第三方分享功能,在iOS9/10下就需要增加一个可跳转的白名单,即LSApplicationQueriesSchemes,否则将在SDK判断是否跳转时用到的canOpenURL时返回NO,进而只进行webview授权或授权/分享失败。在项目中的info.plist中加入应用白名单,右键info.plist选择source code打开(plist具体设置在Build Setting -> Packaging -> Info.plist File可获取plist路径)请根据选择的平台对以下配置进行裁剪:


LSApplicationQueriesSchemes
    /**!-- 微信 URL Scheme 白名单*/
    wechatweixin
    /** 新浪微博 URL Scheme 白名单*/
    sinaweibohdsinaweibosinaweibossoweibosdkweibosdk2.5
    /** QQ、Qzone URL Scheme 白名单*/
    mqqapimqqmqqOpensdkSSoLoginmqqconnectmqqopensdkdatalinemqqopensdkgrouptribesharemqqopensdkfriendmqqopensdkapimqqopensdkapiV2mqqopensdkapiV3mqqopensdkapiV4mqzoneopensdkwtloginmqqwtloginmqq2mqqwpamqzonemqzonev2mqzonesharewtloginqzonemqzonewxmqzoneopensdkapiV2mqzoneopensdkapi19mqzoneopensdkapimqqbrowsermttbrowsertimtimapitimopensdkfriendtimwpatimgamebindinggrouptimapiwallettimOpensdkSSoLoginwtlogintimtimopensdkgrouptribesharetimopensdkapiV4timgamebindinggrouptimopensdkdatalinewtlogintimV1timapiV1
    /** 支付宝 URL Scheme 白名单*/
    alipayalipayshare
    /** 钉钉 URL Scheme 白名单*/
      dingtalkdingtalk-open
    /** Linkedin URL Scheme 白名单*/
    linkedinlinkedin-sdk2linkedin-sdk
    /** 点点虫 URL Scheme 白名单*/
    laiwangsso
    /** 易信 URL Scheme 白名单*/
    yixinyixinopenapi
    /** instagram URL Scheme 白名单*/
    instagram
    /** whatsapp URL Scheme 白名单*/
    whatsapp
    /** line URL Scheme 白名单*/
    line
    /** Facebook URL Scheme 白名单*/
    fbapifb-messenger-apifb-messenger-share-apifbauth2fbshareextension
    /** Kakao URL Scheme 白名单,注:以下第一个参数需替换为自己的kakao appkey,格式为 kakao + "kakao appkey*/
    kakaofa63a0b2356e923f3edd6512d531f546kakaokompassauthstorykompassauthkakaolinkkakaotalk-4.5.0kakaostory-2.9.0
   /** pinterest URL Scheme 白名单*/ 
    pinterestsdk.v1
   /** Tumblr URL Scheme 白名单*/  
    tumblr
   /** 印象笔记 */
    evernoteenenxevernotecidevernotemsg
   /** 有道云笔记*/
    youdaonoteynotedictfavcom.youdao.note.todayViewNoteynotesharesdk
   /** Google+*/
    gplus
   /** Pocket*/
    pocketreaditlaterpocket-oauth-v1fb131450656879143en-readitlater-5776com.ideashower.ReadItLaterPro3com.ideashower.ReadItLaterProcom.ideashower.ReadItLaterProAlphacom.ideashower.ReadItLaterProEnterprise
   /** VKontakte*/
    vkvk-sharevkauthorize
   /** Twitter*/
    twittertwitterauth

配置URL Scheme

  • URL Scheme是通过系统找到并跳转对应app的一类设置,通过向项目中的info.plist文件中加入URL types可使用第三方平台所注册的appkey信息向系统注册你的app,当跳转到第三方应用授权或分享后,可直接跳转回你的app。

  • 添加URL Types可工程设置面板设置

image

权限配置

微博

从微博SDk 3.2.1,即U-Share 6.9.1版开始,支持微博分享多张图片。需在 info.plist 文件中配置相册权限


/** NSPhotoLibraryUsageDescription */
/** App需要您的同意,才能访问相册 */

初始化配置

应用启动后,需要在AppDelegate.m里面配置对应平台的AppKey和AppSecret


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self configChannel];
    return YES;
}

- (void)configChannel{
    LFBShareChannelConfig *config = [[LFBShareChannelConfig alloc]init];
    [[LFBChannelManager sharedManager] setDelegate:config];
    [config setChannelType:LFBChannelTypeWX appKey:@"wx515bbc9e05bf9dx80" appSecret:@"1d44d80947bb3821506e440116f73168"];
    [config setChannelType:LFBChannelTypePYQ appKey:@"wx515bbc9e05bf9dx80" appSecret:@"1d44d80947bb3821506e440116f73168"];
    [config setChannelType:LFBChannelTypeQQ appKey:@"1101053347" appSecret:nil];
    [config setChannelType:LFBChannelTypeQQZone appKey:@"1101053237" appSecret:nil];
    [config setChannelType:LFBChannelTypeSinaWB appKey:@"1843261032" appSecret:@"b2f5b2b661babaa3c01b57312decffd7"];
}

设置系统回调


- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{
    if (@available(iOS 9.0, *)) {
        return  [self handlerOuterURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
    }
    return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [self handlerOuterURL:url sourceApplication:nil];
}

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

- (BOOL)handlerOuterURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication{
    return [[LFBChannelManager sharedManager] handleOpenURL:url];
}

基本使用

当用户自定义分享渠道时,有两种调用方式分别如下:

  • 带Block回调


    LFBSharePlateforms *model = [[LFBSharePlateforms alloc]init];
    model.shareType = LFBChannelTypeWX;
    model.shareInfoType = LFBShareInfoTypeApplet;
    model.title = @"小程序";
    model.text = @"大家来找茬!!!";
    model.webPageUrl [email protected]"https://tapi.liufuboExample.com/activefront/qrcode/shared_car_get_coupon?coupon_template_id=115";
    model.userName = @"gh_a4ff22eef403";
    model.path = @"pages/getcoupon?coupon_template_id=115";
    model.hdImageData = nil;
    model.withShareTicket = YES;
    model.miniProgramType = LFBShareMiniInfoTypeRelease;
    [LFBShareMoudle shareObject:model completion:^(id sender, LFBChannelType channelType, LFBShareState shareState) {

    }];

  • 不带block的调用方式


    LFBSharePlateforms *model = [[LFBSharePlateforms alloc]init];
    model.shareType = LFBChannelTypeWX;
    model.shareInfoType = LFBShareInfoTypeApplet;
    model.title = @"小程序";
    model.text = @"大家来找茬!!!";
    model.webPageUrl [email protected]"https://tapi.liufuboExample.com/activefront/qrcode/shared_car_get_coupon?coupon_template_id=115";
    model.userName = @"gh_a4ff22eef403";
    model.path = @"pages/getcoupon?coupon_template_id=115";
    model.hdImageData = nil;
    model.withShareTicket = YES;
    model.miniProgramType = LFBShareMiniInfoTypeRelease;
    [LFBShareMoudle shareObject:model];

使用框架自带UI分享时,调用方式如下:



    LFBSharePlateforms *model = [[LFBSharePlateforms alloc]init];
    model.shareType = LFBChannelTypeWX;
    model.shareInfoType = LFBShareInfoTypeApplet;
    model.title = @"小程序";
    model.text = @"大家来找茬!!!";
    model.webPageUrl [email protected]"https://tapi.liufuboExample.com/activefront/qrcode/shared_car_get_coupon?coupon_template_id=115";
    model.userName = @"gh_a4ff22eef403";
    model.path = @"pages/getcoupon?coupon_template_id=115";
    model.hdImageData = nil;
    model.withShareTicket = YES;
    model.miniProgramType = LFBShareMiniInfoTypeRelease;
    [LFBShareMoudle showShareViewWithObject:model];

关于登陆功能的使用方法:



   [LFBShareMoudle loginWithChannelType:LFBChannelTypeWX success:^(LFBChannelBase *channel, id data) {
        LFBUserInfo *userInfo = data;
        NSLog(@"%@",userInfo.nickname);
    } fail:^(LFBChannelBase *channel, NSError *error) {
        NSLog(@"%@",error);
    } cancel:^(LFBChannelBase *channel) {
        NSLog(@"取消操作");
    }];

总结: 该框架还处于刚开始迭代的过程中,肯定有很多不足的地方,如在使用过程中遇到问题或者有更好的建议,欢迎issue我,你的issue才是我前进的动力~! thanks

Latest podspec

{
    "name": "LFBSocialSDK",
    "version": "1.0.0",
    "summary": "u4e00u6b3eu63d0u4f9bu5206u4eabu548cu7b2cu4e09u65b9u767bu9646u670du52a1u7684u6846u67b6",
    "description": "u7b80u5355u6613u5bb9u7684u5206u4eabu6846u67b6uff0cu76eeu524du63d0u4f9bu5faeu4fe1u3001nu670bu53cbu5708u3001QQu3001QQu7a7au95f4u3001u65b0u6d6au5faeu535au5206u4eabu670du52a1uff0cnu540cu65f6u4e5fu63d0u4f9bu4e86u7b2cu4e09u65b9u767bu5f55u529fu80fdnu6301u7eedu66f4u65b0u4e2d...",
    "homepage": "https://github.com/LiuFuBo1991/LFBSocialSDK",
    "license": "MIT",
    "authors": {
        "liufubo": "[email protected]"
    },
    "social_media_url": "http://www.jianshu.com/u/7d935e492eec",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/LiuFuBo1991/LFBSocialSDK.git",
        "tag": "1.0.0"
    },
    "source_files": [
        "LFBSocialSDK",
        "LFBSocialSDK/**/*.{h,m}"
    ],
    "public_header_files": "LFBSocialSDK/**/*.h",
    "requires_arc": true,
    "dependencies": {
        "WechatOpenSDK": [
            "~> 1.8.4"
        ],
        "TencentOpenAPI": [
            "~> 1.0.0"
        ],
        "WeiboSDK": [
            "~> 3.1.3"
        ],
        "Masonry": [
            "~> 1.1.0"
        ]
    }
}

Pin It on Pinterest

Share This