How to import LinkedIn SDK in a Swift project?

旧时模样 提交于 2020-01-01 14:35:26

问题


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.

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>

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

import LinkedIn
import LISDK

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

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

Thanks for the help!

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

回答1:


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


来源:https://stackoverflow.com/questions/34222196/how-to-import-linkedin-sdk-in-a-swift-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!