简体   繁体   English

如何在Swift项目中导入LinkedIn SDK?

[英]How to import LinkedIn SDK in a Swift project?

I need to add the LinkedIn SDK into my Swift project. 我需要将LinkedIn SDK添加到我的Swift项目中。 I've downloaded their latest version (1.0.4), dragged and dropped the SDK files into XCode (with "Copy items if needed" and "Add to target" checked). 我已经下载了他们的最新版本(1.0.4),将SDK文件拖放到XCode中(如果需要“复制项目”和“添加到目标”)。 I can see the framework in the "Linked Frameworks and Libraries" section of my target. 我可以在目标的“链接框架和库”部分中看到该框架。

I'm stuck though when I need to import the headers in one swift file. 当我需要在一个swift文件中导入标题时,我陷入困境。 There is an Objective C example in the LinkedIn documentation: LinkedIn文档中有一个Objective C示例:

#import <linkedin-sdk/LISDK.h>

But how would you do it in Swift? 但你怎么在Swift中做到这一点? I've tried different names but they all raise an error. 我尝试了不同的名字,但都引发了错误。

import LinkedIn
import LISDK

"import linkedin-sdk" fails because of the dash ( - ). 由于破折号( - ),“import linkedin-sdk”失败。

I've already imported external frameworks in my project (Parse for instance) and it perfectly worked. 我已经在我的项目中导入了外部框架(例如Parse)并且它完美地工作了。

Thanks for the help! 谢谢您的帮助!

EDIT I do not use LinkedIn API anymore, for they have stopped sharing useful information. 编辑我不再使用LinkedIn API,因为他们已经停止共享有用的信息。 Anyway, here is an old sample of code: 无论如何,这是一个旧的代码示例:

var accessToken: LISDKAccessToken?
func loadAccount(then: (() -> Void)?, or: ((String) -> Void)?) { // then & or are handling closures
    if let token = accessToken {
        LISDKSessionManager.createSessionWithAccessToken(token)
        if LISDKSessionManager.hasValidSession() {
            LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,headline,location,industry,current-share,num-connections,num-connections-capped,summary,specialties,positions,picture-url,picture-urls::(original))?format=json",
                success: {
                    response in
                    print(response.data)
                    then?()
                },
                error: {
                    error in
                    print(error)
                    or?("error")
                }
            )
        }
    } else {
        LISDKSessionManager.createSessionWithAuth([LISDK_BASIC_PROFILE_PERMISSION], state: nil, showGoToAppStoreDialog: true,
            successBlock: {
                (state) in
                self.accessToken = LISDKSessionManager.sharedInstance().session.accessToken
                if LISDKSessionManager.hasValidSession() {
                    LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,headline,location,industry,current-share,num-connections,num-connections-capped,summary,specialties,positions,picture-url,picture-urls::(original))?format=json",
                        success: {
                            response in
                            print(response.data)
                            then?()
                        },
                        error: {
                            error in
                            print(error)
                            or?("error")
                        }
                    )
                }
            },
            errorBlock: {
                (error) in
                switch error.code {
                default:
                    if let errorUserInfo = error.userInfo["error"] as? NSString {
                        or?(errorUserInfo as String)
                    } else {
                        or?(UIError.Code.Unknown)
                    }
                }
            }
        )
    }
}

Man, you should have a bridging header . 伙计,你应该有一个桥头 Mine looks as simple as that: 我看起来很简单:

//  Copyright © 2015 Arthur Gevorkyan. All rights reserved.
//

#ifndef BridgingHeader_h
#define BridgingHeader_h

#import <Foundation/Foundation.h>
#import <linkedin-sdk/LISDK.h>


#endif /* BridgingHeader_h */

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

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