import UIKit
import Firebase
import FirebaseAuth
import FBSDKLoginKit
import FBSDKCoreKit
class LoginViewController: UIViewController, UITextFieldDelegate, FBSDKLoginButtonDelegate {
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if let error = error {
print(error.localizedDescription)
return
}
/*
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
Auth.auth().signIn(with: credential) { (user, error) in
/*
if let error = error {
// ...
return
}
// User is signed in
// ...
print("Login facebook ok")
self.dismiss(animated: true, completion: nil)
*/
}
*/
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
do {
try Auth.auth().signOut()
} catch {
print ("Logout fel")
}
}
@IBOutlet weak var epostTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var forgotPassword: UIButton!
@IBOutlet weak var registrera: UIButton!
@IBOutlet weak var loggaIn: UIButton!
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == epostTextField{
passwordTextField.becomeFirstResponder()
}else{
passwordTextField.resignFirstResponder()
}
return true
}
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = FBSDKLoginButton()
loginButton.delegate = self
view.addSubview(loginButton)
loginButton.frame = CGRect(x: 16, y: 300, width: view.frame.width - 32, height: 50)
self.epostTextField.delegate = self
self.passwordTextField.delegate = self
let tap = UITapGestureRecognizer(target: self, action: #selector(hideKeyBoard))
self.view.addGestureRecognizer(tap)
// Do any additional setup after loading the view.
epostTextField.font = UIFont(name:"BebasNeue", size: 20)
passwordTextField.font = UIFont(name:"BebasNeue", size: 20)
forgotPassword.titleLabel?.font = UIFont (name: "BebasNeue", size: 20)
registrera.titleLabel?.font = UIFont (name: "BebasNeue", size: 20)
loggaIn.titleLabel?.font = UIFont (name: "BebasNeue", size: 20)
}
@objc func hideKeyBoard(sender: UITapGestureRecognizer? = nil){
view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func loggaIn(_ sender: Any) {
Auth.auth().signIn(withEmail: epostTextField.text!, password:
passwordTextField.text!){
(user, error) in
if(error != nil)
{
let alert = UIAlertController(title: "Fel vid inloggning", message: "Felaktig e-post eller lösenord", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
print("Fel vid Login")
} else {
print("Login ok")
self.dismiss(animated: true, completion: nil)
}
}
}
@IBAction func registrera(_ sender: Any) {
Auth.auth().createUser(withEmail: epostTextField.text!, password:
passwordTextField.text!) {
(user, error) in
if(error != nil)
{
print("Fel vid registrering")
} else {
print("Registrering ok")
self.dismiss(animated: true, completion: nil)
}
}
}
@IBAction func forgotPassword(_ sender: Any) {
let alert = UIAlertController(title: "Information", message: "Nytt lösenord skickat", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
`Im using Swift 4 and Xcode 9.
所以我已经完成了Facebook开发人员的所有步骤,并遵循了firebase步骤。
所以现在,在上面的代码中,我转移到Facebook,并且可以登录,但是当我回到应用程序时,我仍然在loginviewcontroller中,我没有被发送到下一个viewController。如果我尝试取消注释上面图片中的代码,当我在Facebook登录后尝试返回应用程序时,一切都会崩溃。这就是我收到此错误消息时的情况。
2017-10-31 16:02:49.768994 + 0100愿望[1479:446286] *终止 应用程序由于未捕获的异常' NSInvalidArgumentException',原因: ' - [__ NSDictionaryM gtm_httpArgumentsString]:无法识别的选择器 发送到实例0x1c42203c0' * 第一次抛出调用堆栈:(0x182047d38 0x18155c528 0x1820551f8 0x18204d6e4 0x181f330dc 0x100568b58 0x100563910 0x100562768 0x100561860 0x10054dab4 0x10054d728 0x10054d47c 0x101be149c 0x101be145c 0x101bf0110 0x101be49a4 0x101bf1104 0x101bf8100 0x181c72fe0 0x181c72c30)libc ++ abi.dylib:以未捕获终止 NSException类型的异常(lldb)
我需要严肃的帮助,我正在学习应用程序开发atm,而我的老师甚至无法解决这个问题