简体   繁体   English

LinkedIn SDK iOS Swift

[英]LinkedIn SDK ios swift

I am trying to integrate LinkedIn SDK in iOS using swift 我正在尝试使用Swift将iOS中的LinkedIn SDK集成

I found the below code in objective-C ( https://developer.linkedin.com/docs/signin-with-linkedin ) 我在Objective-C( https://developer.linkedin.com/docs/signin-with-linkedin )中找到了以下代码

NSString *url = [NSString initWithString:@"https://api.linkedin.com/v1/people/~"];
if ([LISDKSessionManager hasValidSession]) {
    [[LISDKAPIHelper sharedInstance] getRequest:url
    success:^(LISDKAPIResponse *response) {
        // do something with response
    }
    error:^(LISDKAPIError *apiError) {
        // do something with error
    }];
]}

How to convert this to swift. 如何将其转换为快速。

I am very new to swift 我是新手

var url = NSString(string:"https://api.linkedin.com/v1/people/~")

if LISDKSessionManager.hasValidSession {
    LISDKAPIHelper.sharedInstance().getRequest(url, success: {
        response in
        //Do something with the response
    }, error: {
        error in
        //Do something with the error
    })
}

This (I think its correct) is the translated version. 这(我认为是正确的)是翻译版本。 I don't know Objective-C, I just used my knowledge of Swift to try and figure this out. 我不了解Objective-C,我只是用我对Swift的了解来尝试解决这个问题。

Have you learned about closures yet? 您了解闭包了吗? If not, I don't recommend using SDKs like the LinkedIn one because they rely on closures for many networking requests. 如果没有,我不建议使用像LinkedIn这样的SDK,因为它们依赖于闭包来处理许多网络请求。 I'd check out Treehouse Inc. , a coding course site which offers great courses on closures in Swift (along with a bunch of other stuff). 我会去Treehouse Inc. ,这是一个编码课程站点,其中提供了有关Swift中的闭包的出色课程(以及许多其他内容)。

var url = "https://api.linkedin.com/v1/people/~"

if LISDKSessionManager.hasValidSession() 
{
 try? LISDKAPIHelper.sharedInstance().getRequest(url, success: {(_ response: LISDKAPIResponse) -> Void in
        // do something with response
    })
}

this is in swift 4 这是迅速4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM