You need to give permissions and after that, you need to call graph API (FBSDKGraphRequest) to get the profile images.
I have prepared a class, You can achieve your requirement from this class:
import UIKit
import FBSDKCoreKit
import FacebookCore
import FacebookLogin
class LoginWithFacebook {
// MARK: - Properties
static let sharedInstance = LoginWithFacebook()
/**
Takes user to the facebook login page so that user could login with his facebook credentials and brings back basic details of the user and photo album
- parameter viewControl: controller on which the facebook page will be opened
- parameter completion: on completion the method returns user info in the form of dictionary
*/
public func fBLoginWithPhotoAlbum(viewControl: UIViewController, completion: @escaping ([String: Any]) -> Void) {
var responseDictionary: [String: Any] = [String: Any]()
let loginManager = LoginManager()
loginManager.logIn(readPermissions: [.publicProfile, .email, .userFriends, .custom("user_birthday")], viewController: viewControl) { (loginResult) in
print(loginResult)
switch loginResult {
case .failed(let error):
print(error)
case .success(grantedPermissions: _, declinedPermissions: _, token: let accessToken) :
responseDictionary.updateValue(accessToken.authenticationToken, forKey: "accessToken")
let param = ["fields": "first_name, last_name, picture.width(9999), email, friends, gender, age_range, birthday, photos{album,picture}"]
FBSDKGraphRequest.init(graphPath: "me", parameters: param).start { (_, result, _) -> Void in
if let resultDictionary: NSDictionary = result as? NSDictionary {
responseDictionary.updateValue(resultDictionary, forKey: "userInfo")
FBSDKGraphRequest.init(graphPath: "me/albums", parameters: ["fields": "photos{picture}"], httpMethod: "GET").start(completionHandler: { (_, result, _) in
let data = (result as? NSDictionary)?.value(forKey: "data") as? NSArray
if (data?.count)! > 0 {
var profileAlbum: [Any] = data!.filter { NSPredicate(format: "(name == %@) ", "Profile Pictures").evaluate(with: $0) }
if profileAlbum.count > 0 {
if let profilePicAlbum = profileAlbum[0] as? NSDictionary {
let graphPath = profilePicAlbum.value(forKey: "id")
//picture, "photos{link}"
let param = ["fields": "photos{picture}"]
FBSDKGraphRequest.init(graphPath: graphPath as? String, parameters: param, httpMethod: "GET").start(completionHandler: { (_, result, _) in
if let profilePicArray = (result as? NSDictionary)?.value(forKeyPath: "photos.data") {
responseDictionary.updateValue(profilePicArray, forKey: "profilePics")
completion(responseDictionary)
}
})
}
}
} else {
completion(responseDictionary)
}
})
} else {
}
}
case .cancelled :
completion(["message": "Something Went Wrong"])
}
}
}
}