本文介绍了如何在Swift项目中导入LinkedIn SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to add the LinkedIn SDK into my Swift project. 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). I can see the framework in the "Linked Frameworks and Libraries" section of my target.

当我需要在一个快速文件中导入标头时,我陷入了困境. LinkedIn文档中有一个Objective C示例:

I'm stuck though when I need to import the headers in one swift file. There is an Objective C example in the LinkedIn documentation:

#import <linkedin-sdk/LISDK.h>

但是您将如何在Swift中做到这一点?我尝试过使用不同的名称,但是它们都会引发错误.

But how would you do it in Swift? I've tried different names but they all raise an error.

import LinkedIn
import LISDK

由于破折号(-),"importlinkedin-sdk"失败.

"import linkedin-sdk" fails because of the dash ( - ).

我已经在项目中导入了外部框架(例如Parse),并且效果很好.

I've already imported external frameworks in my project (Parse for instance) and it perfectly worked.

感谢您的帮助!

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

EDITI do not use LinkedIn API anymore, for they have stopped sharing useful information. 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 */

这篇关于如何在Swift项目中导入LinkedIn SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:34