Skip to content

poholo/MCDingTalk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCDingTalk

钉钉(DingTalk)分享、授权SDK

用法

  1. Info.plist配置查询钉钉授权登录scheme权限。LSApplicationQueriesSchemes中添加dingtalk, dingtalk-open, dingtalk-sso。dingtalk用于查询是否安装钉钉。dingtalk-open用于查询是否支持开放平台接口调用(不需要查询开放平台接口可不填)。dingtalk-sso用于查询是否支持授权登录。注:iOS系统限制LSApplicationQueriesSchemes最多只能有50个,超出的话会有一部分不生效。 如图: undefined

  2. Info.plist的URL Types中增加appId,用于钉钉App返回回调。 undefined

  3. app启动时注册appId。示例代码:

// 在app启动时注册appId
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // 注册AppId;
    [DTOpenAPI registerApp:#该应用的appId#];
    return YES;
}
  1. 发起授权登录。示例代码:
DTAuthorizeReq *authReq = [DTAuthorizeReq new];
authReq.bundleId = #该应用的bundleId#;
  1. 处理回调。示例代码:
// 在app delegate链接处理回调中调用钉钉回调链接处理方法
- (BOOL)application:(UIApplication *)application
            openURL:(nonnull NSURL *)url
  sourceApplication:(nullable NSString *)sourceApplication
         annotation:(nonnull id)annotation
{
    if ([DTOpenAPI handleOpenURL:url delegate:self]) {
        return YES;
    }
 
    return NO;
}
// delegate实现回调处理方法 onResp:
- (void)onResp:(DTBaseResp *)resp
{
  //授权登录回调参数为DTAuthorizeResp,accessCode为授权码
    if ([resp isKindOfClass:[DTAuthorizeResp class]]) {
        DTAuthorizeResp *authResp = (DTAuthorizeResp *)resp;
        NSString *accessCode = authResp.accessCode;
		// 将授权码交给服务端做SSO
    }
}

updates

1.0.1 更新依赖方式(pod版),支持最新的sdk

doc & sdk

share auth

Author

littleplayer mailjiancheng@163.com

License

MCDingTalk is available under the MIT license. See the LICENSE file for more info.