我有登录功能,当用户有效时我没有问题,但是当用户是isvalid
我有这个错误
“由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished]只能从主线程调用。”
这是我的代码。
@IBAction func login(sender: AnyObject) {
var valid: Bool = false
//activity.startAnimating()
self.viewUtils.showActivityIndicator(self.view)
username = userField.text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
password = passwordTextField.text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
if (self.username.isEmpty || self.password.isEmpty){
self.showAlert("Inserte usuario password")
}
else{
var user = UserFunction()
user.userValid(self.username,password: self.password){ success in
if success == true{
//self.activity.stopAnimating()
self.performSegueWithIdentifier("showTable", sender: self )
}else{
println("me quedo aqui")
//self.activity.stopAnimating()
self.showAlert("usuario incorrecto")//ver porque no entra a usuario incorrecto
}
}
}
}
func userValid(username :String, password : String, completionHandler:(Bool)->()){
var valid: Bool!
var resultados : Array<JSON> = []
userBase64 = self.encodeToBase64(username)
passBase64 = self.encodeToBase64(password)
var api = ChannelsFunction()
api.loadVideos("https://api.cxntv.com/api/v1/videos/?type=canales&page_size=100&ordering=-id"){results in
if (results != nil){
errorMessage = ""
println("devuelvo true")
api.saveLiveChannels(results!)
self.saveUser(userBase64, passbase64: passBase64, username: username, password: password)
completionHandler(true)
}else{
println("devuelvo false")
completionHandler(false)
}
}
}