我需要将LinkedIn SDK添加到我的Swift项目中。我已经下载了它们的最新版本(1.0.4),将SDK文件拖放到XCode中(选中了“如果需要,复制项目”和“添加到目标”)。我可以在目标的“链接的框架和库”部分中看到该框架。
但是,当我需要在一个快速文件中导入标头时,我陷入了困境。LinkedIn文档中有一个Objective C示例:
#import <linkedin-sdk/LISDK.h>
但是,您将如何在Swift中做到这一点?我尝试过使用不同的名称,但是它们都会引发错误。
import LinkedIn
import LISDK
由于破折号(-),“ importlinkedin-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)
}
}
}
)
}
}
伙计,您应该有一个桥接头。我的看起来很简单:
// 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 */
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句