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

标签 ios xcode swift linkedin

我需要将 LinkedIn SDK 添加到我的 Swift 项目中。我已经下载了他们的最新版本 (1.0.4),将 SDK 文件拖放到 XCode 中(选中“如果需要复制项目”和“添加到目标”)。我可以在我的目标的“链接框架和库”部分看到该框架。

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

#import <linkedin-sdk/LISDK.h>

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

import LinkedIn
import LISDK

“导入 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 */

关于ios - 如何在 Swift 项目中导入 LinkedIn SDK?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34222196/

相关文章:

ios - ionic Facebook 身份验证 - iOS - 应用程序未设置 : Still in Dev Mode

ios - 如何在 iOS 的 Collection View 中从底部删除多余的空间?

iphone - UIPickerView 获取 "Clicked"元素?

swift - 有什么方法可以确定子协议(protocol)的一致性,例如是否符合 Swift 2 中的通用协议(protocol)(在运行时或编译期间)?

ios - 如何使用 Swift 和 parse.com 在 tableview 中显示图像

ios - 如何检查是否给出了正确的链接

ios - 将方法标记为已弃用

Xcode 从命令行构建应用程序

ios - 刚刚选择图片后,如何不对 viewDidAppear 执行查询?

swift - 如何以编程方式将文本设置为 NSTextView 中的超链接? swift 4、Xcode 9.4