вот простое решение
import UIKit
import LinkedinSwift
class ViewController: UIViewController {
private let linkedinHelper = LinkedinSwiftHelper(configuration: LinkedinSwiftConfiguration(clientId: "Your client id", clientSecret: "yout clientSecret", state: "DLKDJF46ikMMZADfdfds", permissions: ["r_basicprofile", "r_emailaddress"], redirectUrl: "your project or your company any project url"))
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func btnClicked(_ sender: UIButton) {
linkedinHelper.authorizeSuccess({ (token) in
print(token)
//This token is useful for fetching profile info from LinkedIn server
self.linkedinHelper.requestURL("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,picture-urls::(original),positions,date-of-birth,phone-numbers,location)?format=json", requestType: LinkedinSwiftRequestGet, success: { (response) -> Void in
print(response)
//parse this response which is in the JSON format
// self.linkedinHelper.logout() //logout session
let cookie = HTTPCookie.self
let cookieJar = HTTPCookieStorage.shared
for cookie in cookieJar.cookies! {
// print(cookie.name+"="+cookie.value)
cookieJar.deleteCookie(cookie)
}
}) {(error) -> Void in
print(error.localizedDescription)
//handle the error
}
}, error: { (error) in
print(error.localizedDescription)
//show respective error
}) {
//show sign in cancelled event
}
}
}
и добавьте метод в Appdelegate
import LinkedinSwift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if LinkedinSwiftHelper.shouldHandle(url) {
return LinkedinSwiftHelper.application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
}
return true
}
просто нужно добавить модуль: -
pod 'LinkedinSwift'