A share auth wheels based on the official library content wecaht sina tencent facebook twitter google MI Line
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DDSocial
DDSocialCodeDemo
DDSocialDemoCore
DDSocialPodDemo
小米登录逻辑.mindnode
.gitignore
.swift-version
DDSocial.podspec
LICENSE
README.md
aboutme.txt
小米登录逻辑.png

README.md

DDSocial

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或appID根据三方平台决定"redirectURL:@"申请时填写的URL"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformWeChat appKey:@"自己申请的key或appID根据三方平台决定"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformSina appKey:@"自己申请的key或appID根据三方平台决定"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformQQ appKey:@"自己申请的key或appID根据三方平台决定"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformFacebook appKey:@"自己申请的key或appID根据三方平台决定"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformTwitter appKey:@"自己申请的key或appID根据三方平台决定" appSecret:@"对应的secret"];
    [[DDSocialShareHandler sharedInstance] registerPlatform:DDSSPlatformGoogle appKey:@"自己申请的CLIENT_ID或appID根据三方平台决定"];
    [[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)添加CFBundleURLTypes
  (2)添加NSAppTransportSecurity字段
3、示例代码


<dict>
	<key>CFBundleTypeRole</key>
	<string>MI</string>
	<key>CFBundleURLName</key>
	<string>xiaomi</string>
	<key>CFBundleURLSchemes</key>
	<array>
		<string>miXXXXXXXXX</string>
	</array>
</dict>

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>open.account.xiaomi.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>www.miui.com</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
          <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
          <true/>
        </dict>
    </dict>
</dict>

微信开放平台(https://open.weixin.qq.com/)

1、首先在微信开放平台根据自己app的bundleid申请一个appkey
2、然后在xcode中配置info.plist
(1)添加CFBundleURLTypes
(2)添加LSApplicationQueriesSchemes白名单
3、示例代码


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>WeChat</string>
        <key>CFBundleURLName</key>
        <string>weixin</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>替换成自己的appkey</string>
        </array>
    </dict>
</array>

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>weixin</string>
        <string>weichat</string>
    </array>

QQ互联(http://connect.qq.com/)

1、首先在QQ互联申请appkey
2、然后在xcode中配置info.plist
(1)添加CFBundleURLTypes
(2)添加LSApplicationQueriesSchemes白名单
3、示例代码


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Tencent</string>
        <key>CFBundleURLName</key>
        <string>tencentopenapi</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>替换成自己的appkey</string>
        </array>
    </dict>
</array>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>mqqOpensdkSSoLogin</string>
    <string>mqqopensdkapiV2</string>
    <string>mqqopensdkapiV3</string>
    <string>mqq</string>
    <string>mqqapi</string>
    <string>wtloginmqq2</string>
    <string>mqzone</string>
    <string>tim</string>
    <string>timapiV1</string>
</array>

新浪微博开放平台(http://open.weibo.com/)

1、首先在新浪微博开放平台申请appkey 可以选择配置自己的redirectURL
2、然后在xcode中配置info.plist
(1)添加CFBundleURLTypes
(2)添加LSApplicationQueriesSchemes白名单
3、示例代码


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Sina</string>
        <key>CFBundleURLName</key>
        <string>com.weibo</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>替换成自己的appkey</string>
        </array>
    </dict>
</array>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>sinaweibosso</string>
    <string>sinaweibohdsso</string>
    <string>sinaweibo</string>
    <string>weibosdk</string>
    <string>weibosdk2.5</string>
    <string>sinaweibohd</string>
</array>

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、示例代码


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>REVERSED_CLIENT_ID</string>
        </array>
    </dict>
</array>

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、示例代码


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>FB</string>
        <key>CFBundleURLName</key>
        <string>facebook</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>替换成自己的appkey</string>
        </array>
    </dict>
</array>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbshareextension</string>
    <string>fbauth2</string>
    <string>fb-messenger-api</string>
    <string>fbapi</string>
</array>
<key>FacebookAppID</key>
<string>替换成自己的appkey</string>
<key>FacebookDisplayName</key>
<string>facebook授权页展示的名字</string>

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、示例代码


<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        </array>
    </dict>
</array>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>lineauth</string>
    <string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <string>line</string>
</array>
</dict>

<key>LineSDKConfig</key>
<dict>
    <key>ChannelID</key>
 	<string>自己申请的LineID</string>
</dict>  

Instagram开放平台(目前只支持图片分享,暂不支持授权)(//https://www.instagram.com/developer/mobile-sharing/iphone-hooks/)

1、在xcode中配置info.plist
(1)添加LSApplicationQueriesSchemes白名单
3、示例代码


<key>LSApplicationQueriesSchemes</key>
<array>
    <string>instagram</string>
</array>
</dict>