我需要将 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/