UICollectionViewCell内でFBSDKを使用する際に問題が発生しています。コードがreturn文の後に実行されないという警告が表示されます。私はUIViewControllerでFacebookログインを実装しましたが、CollectionViewCellクラスの内部でそれをしようとするとエラーが発生しています。すべての助けをありがとう!オブジェクトをUICollectionViewCellに渡します。
class LoginCell: UICollectionViewCell, FBSDKLoginButtonDelegate {
lazy var FBloginButton: UIButton = {
let customButton = UIButton(type: .system)
customButton.backgroundColor = UIColor.blue
customButton.setTitle("Login With Facebook", for: .normal)
customButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
customButton.setTitleColor(.white, for: .normal)
return customButton
customButton.addTarget(self, action: #selector(handleCustomFBButton), for: .touchUpInside)
}()
// am I passing an objective from: correctly below...????
func handleCustomFBButton() {
FBSDKLoginManager().logIn(withReadPermissions: ["email", "public_profile"], from: self.delegate as! UIViewController!) { (result, err) in
if err != nil {
print("Custom FB Login Button Failed")
return
}
self.showEmailAddress()
}
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
print("did log out of facebook...")
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if error != nil {
print(error)
return
}
showEmailAddress()
}
func showEmailAddress() {
let accessToken = FBSDKAccessToken.current()
guard let accessTokenString = accessToken?.tokenString else { return }
let credentials = FIRFacebookAuthProvider.credential(withAccessToken: accessTokenString)
FIRAuth.auth()?.signIn(with: credentials, completion: { (user, error) in
if error != nil {
print("Something went wrong with our FB user: ", error ?? "")
return
}
print("Successfully logged in with our user: ", user ?? "")
})
FBSDKGraphRequest(graphPath: "/me", parameters: ["fields": "id, name, email"]).start { (connection, result, err) in
if err != nil {
print("Failed to start graph request:", err ?? "")
return
}
print(result ?? "")
}
}
weak var delegate: LoginControllerDelegate?
func handleLogin() {
delegate?.finishLoggingIn()
}
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(logoImageView)
addSubview(emailTextField)
addSubview(passwordTextField)
addSubview(loginButton)
addSubview(FBloginButton)
_ = logoImageView.anchor(centerYAnchor, left: nil, bottom: nil, right: nil, topConstant: -230, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 160, heightConstant: 160)
logoImageView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
_ = FBloginButton.anchor(loginButton.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 16, leftConstant: 32, bottomConstant: 0, rightConstant: 32, widthConstant: 0, heightConstant: 50)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}