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

How to import LinkedIn SDK in a Swift project?

我需要将 LinkedIn SDK 添加到我的 Swift 项目中。我已经下载了他们的最新版本 (1.0.4),将 SDK 文件拖放到 XCode 中(选中 "Copy items if needed" 和 "Add to target")。我可以在目标的 "Linked Frameworks and Libraries" 部分看到框架。

当我需要在一个 swift 文件中导入 headers 时,我被卡住了。 LinkedIn 文档中有一个 Objective C 示例:

#import <linkedin-sdk/LISDK.h>

但是在 Swift 中你会怎么做?我尝试了不同的名称,但它们都引发了错误。

import LinkedIn
import LISDK

"import linkedin-sdk" 由于破折号 (-) 而失败。

我已经在我的项目中导入了外部框架(例如 Parse)并且它运行良好。

感谢您的帮助!

编辑 我不再使用 LinkedIn API,因为他们已停止分享有用的信息。无论如何,这是一个旧的代码示例:

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

伙计,你应该有一个bridging header。我的看起来就这么简单:

//  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 */