DDSocial 1.6.3

DDSocial 1.6.3

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jan 2018

Maintained by llg.



DDSocial 1.6.3

  • By
  • llg

A share auth wheels based on the official library content wecaht sina tencent facebook twitter google mi
#Warning
1、新版TencentSDK不支持模拟器,所以只能使用真机调试
#使用
##使用配置
1、引入类库,必须引入share模块,其他可根据自身app选择性引入

(1)使用pod形式引入
全部引入


	pod 'DDSocial' 
单个引入

	pod 'DDSocial/Share' 
	pod 'DDSocial/MI'
	pod 'DDSocial/Wechat'
	pod 'DDSocial/Tencent'
	pod 'DDSocial/Sina'
	pod 'DDSocial/Facebook'
	pod 'DDSocial/Twitter'
	pod 'DDSocial/Google'
	pod 'DDSocial/Line'
	pod 'DDSocial/Instagram'

(2)使用源文件需要配置类库的Search Paths

选择使用DDSocial目录下的模块Core是必须依赖的模块

Build Settings -> Search Paths 两个地方添加 Framework Search Paths 和 Library Search Paths
2、在AppDelegate.h中实现如下方法

(1)引入头文件


#import "DDSocialShareHandler.h"

(2)在应用启动时注册第三方


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformMI appKey:@"自己申请的key"redirectURL:@"申请时填写的URL"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformWeChat appKey:@"自己申请的key"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformSina appKey:@"自己申请的key"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformQQ appKey:@"自己申请的key"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformFacebook appKey:@"自己申请的key"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformTwitter appKey:@"自己申请的key" appSecret:@"对应的secret"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformGoogle];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformLine];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformInstagram];
    return YES;
}

(3)实现唤起app回调


- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [[DDSocialShareHandler sharedInstance] application:application handleOpenURL:url sourceApplication:nil annotation:nil];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[DDSocialShareHandler sharedInstance] application:application handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{
    return [[DDSocialShareHandler sharedInstance] application:app openURL:url options:options];
}

##分享
2、调用方式

(1)实现分享的protocol


DDSocialShareTextProtocol//纯文本分享需要实现该协议
DDSocialShareImageProtocol//图片分享需要实现该协议
DDSocialShareWebPageProtocol//web内容分享需要实现该协议

(2)分享代码


[[DDSocialShareHandler sharedInstance] shareWithPlatform:DDSSPlatformWeChat controller:self shareScene:DDSSSceneWXSession contentType:DDSSContentTypeImage protocol:self handler:^(DDSSPlatform platform, DDSSScene scene, DDSSShareState state, NSError *error) {
        switch (state) {
            case DDSSShareStateBegan: {
                NSLog(@"开始分享");
                break;
            }
            case DDSSShareStateSuccess: {
                NSLog(@"分享成功");
                break;
            }
            case DDSSShareStateFail: {
                NSLog(@"分享失败:%@",error);
                break;
            }
            case DDSSShareStateCancel: {
                NSLog(@"取消分享");
                break;
            }
        }
    }];

##授权


[[DDSocialShareHandler sharedInstance] authWithPlatform:DDSSPlatformWeChat authMode:DDSSAuthModeCode controller:self handler:^(DDSSPlatform platform, DDSSAuthState state, DDAuthItem *authItem, NSError *error) {
        switch (state) {
            case DDSSAuthStateBegan: {
                NSLog(@"开始授权");
                break;
            }
            case DDSSAuthStateSuccess: {
                NSLog(@"授权成功:%@",authItem);
                break;
            }
            case DDSSAuthStateFail: {
                NSLog(@"授权失败Error:%@",error);
                break;
            }
            case DDSSAuthStateCancel: {
                NSLog(@"授权取消");
                break;
            }
        }
    }];

#各个平台配置
###小米开放平台(http://dev.xiaomi.com/index)
1、首先在小米开放平台申请appkey并配置好redirectURL

2、然后在xcode中配置info.plist

(1)添加NSAppTransportSecurity字段

3、示例代码


NSAppTransportSecurity

    NSAllowsArbitraryLoads
    
    NSExceptionDomains
    
        open.account.xiaomi.com
        
            NSExceptionAllowsInsecureHTTPLoads
            
        
        www.miui.com
        
          NSIncludesSubdomains
          
          NSThirdPartyExceptionAllowsInsecureHTTPLoads
          
        
    

###微信开放平台(https://open.weixin.qq.com/)
1、首先在微信开放平台根据自己app的bundleid申请一个appkey

2、然后在xcode中配置info.plist

(1)添加CFBundleURLTypes

(2)添加LSApplicationQueriesSchemes白名单

3、示例代码


CFBundleURLTypes

    
        CFBundleTypeRole
        WeChat
        CFBundleURLName
        weixin
        CFBundleURLSchemes
        
            替换成自己的appkey
        
    


LSApplicationQueriesSchemes
    
        weixin
        weichat
    

###QQ互联(http://connect.qq.com/)
1、首先在QQ互联申请appkey

2、然后在xcode中配置info.plist

(1)添加CFBundleURLTypes

(2)添加LSApplicationQueriesSchemes白名单

3、示例代码


CFBundleURLTypes

    
        CFBundleTypeRole
        Tencent
        CFBundleURLName
        tencentopenapi
        CFBundleURLSchemes
        
            替换成自己的appkey
        
    


LSApplicationQueriesSchemes

    mqqOpensdkSSoLogin
    mqqopensdkapiV2
    mqqopensdkapiV3
    mqq
    mqqapi
    wtloginmqq2
    mqzone
    tim
    timapiV1

###新浪微博开放平台(http://open.weibo.com/)
1、首先在新浪微博开放平台申请appkey 可以选择配置自己的redirectURL

2、然后在xcode中配置info.plist

(1)添加CFBundleURLTypes

(2)添加LSApplicationQueriesSchemes白名单

3、示例代码


CFBundleURLTypes

    
        CFBundleTypeRole
        Sina
        CFBundleURLName
        com.weibo
        CFBundleURLSchemes
        
            替换成自己的appkey
        
    


LSApplicationQueriesSchemes

    sinaweibosso
    sinaweibohdsso
    sinaweibo
    weibosdk
    weibosdk2.5
    sinaweibohd

###Google开放平台(https://developers.google.com/identity/sign-in/ios/)
1、首先在google开放平台申请appkey(详细步骤:https://developers.google.com/identity/sign-in/ios/start-integrating#before_you_begin)

2、然后在xcode中配置info.plist

(1)添加CFBundleURLTypes

3、示例代码


CFBundleURLTypes

    
        CFBundleTypeRole
        Editor
        CFBundleURLSchemes
        
            google申请的appkey
        
    
    
        CFBundleTypeRole
        Editor
        CFBundleURLSchemes
        
            google申请的bundle
        
    

1、工程的bundleid必须和申请google的完全一致

2、google需要添加他自己生成的info.plist参见文档操作吧,参见连接:https://developers.google.com/identity/sign-in/ios/start-integrating#before_you_begin

###Facebook开放平台(https://developers.facebook.com/) 详情查看(https://developers.facebook.com/docs/ios/getting-started)
1、首先在Facebook开放平台申请appkey

2、然后在xcode中配置info.plist

(1)添加CFBundleURLTypes

(2)添加LSApplicationQueriesSchemes白名单

(3)添加FacebookAppID

(4)添加FacebookDisplayName

3、示例代码


CFBundleURLTypes

    
        CFBundleTypeRole
        FB
        CFBundleURLName
        facebook
        CFBundleURLSchemes
        
            替换成自己的appkey
        
    


LSApplicationQueriesSchemes

    fbshareextension
    fbauth2
    fb-messenger-api
    fbapi

FacebookAppID
125938537776820
FacebookDisplayName
facebook授权页展示的名字

###Line开放平台(https://developers.line.me/en/docs/line-login/ios/)
1、首先在Line开放平台申请appkey(详细步骤:https://developers.line.me/en/docs/line-login/ios/integrate-line-login/)

2、然后在xcode中配置info.plist

(1)添加CFBundleURLTypes

(2)添加LSApplicationQueriesSchemes白名单

(3)添加LineSDKConfig

3、示例代码


CFBundleURLTypes

    
        CFBundleTypeRole
        Editor
        CFBundleURLSchemes
        
            line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)
        
    


LSApplicationQueriesSchemes

    lineauth
    line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)
    line



LineSDKConfig

    ChannelID
    自己申请的LineID
  

###Instagram开放平台(目前只支持图片分享,暂不支持授权)(//https://www.instagram.com/developer/mobile-sharing/iphone-hooks/)
1、在xcode中配置info.plist

(1)添加LSApplicationQueriesSchemes白名单

3、示例代码


LSApplicationQueriesSchemes

    instagram