-
Notifications
You must be signed in to change notification settings - Fork 0
/
FacebookLoginManager.swift
59 lines (46 loc) · 1.74 KB
/
FacebookLoginManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Foundation
import FBSDKLoginKit
/**
ZvestaPro : FacebookLoginManager
This file is use for facebook login under social login module.
- Author:
Sarabjeet Singh
- Copyright:
Zapbuild Technologies Pvt Ltd
- Date:
17/01/20
- Version:
1.0
*/
class FacebookLoginManager: NSObject{
//MARK:- Variables
var delegate : SocialLoginDelegate?
typealias fbLoginResponse = ([String: Any]?, String?, Error?) -> ()
func loginWithFB(controller:UIViewController, completion: @escaping fbLoginResponse) {
let login = LoginManager()
login.logOut()
login.logIn(permissions: ["public_profile", "email"], from: controller, handler: {(result, error) in
if error != nil {
completion(nil, nil, error)
self.delegate?.errorInSocialLogin(error: error!.localizedDescription)
}
else if (result?.isCancelled)! {
// if the facebook popup actioned with cancel button
}
else {
Logger.log("facebook login success")
let token = result?.token!.tokenString
GraphRequest(graphPath: "me", parameters: ["fields": "first_name, last_name, email, name, id, picture.width(2000).height(2000)"]).start(completionHandler: {(connection, result, error) -> Void in
if error != nil{
completion(nil, nil, error)
}else{
guard let resultDictionary = result as? [String:Any] else {
fatalError("result is not a dictionary")
}
completion(resultDictionary, token, nil)
}
})
}
})
}
}