LinkedIn SDK ios swift

若如初见. 提交于 2019-12-08 07:57:15

问题


I am trying to integrate LinkedIn SDK in iOS using swift

I found the below code in 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


回答1:


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.

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. 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).




回答2:


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



来源:https://stackoverflow.com/questions/31318649/linkedin-sdk-ios-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!