Swift error: "MailCompositionService quit unexpectedly" - ios

The error message screenshot:
When I click the "click here" button in the paragraph that says "If you forgot your username/password, click here to send a verification message that contains your username/password to your email address", the dialogue box pops up and says "MailCompositionService quit unexpectedly", and that message is the error I want to solve.
This class below this sentence is the Swift code for the page that has the "click here" button which generates the error I want to solve. It is the ViewController class.
import UIKit
import MessageUI
class ViewController: UIViewController, MFMailComposeViewControllerDelegate
{
#IBOutlet weak var ClickHereSendEmailButton: UIButton!
#IBOutlet weak var Label: UILabel!
#IBOutlet weak var UsernameTextField: UITextField!
#IBOutlet weak var PasswordTextField: UITextField!
#IBOutlet weak var SignInButton: UIButton!
#IBAction func PressedSignInButton(sender: UIButton)
{
if UsernameTextField.text == username && PasswordTextField.text == password
{
// create the alert
let alert = UIAlertController(title: "Correct", message: "Your credentials are correct.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
Label.text = "The credentials are correct."
UsernameTextField.resignFirstResponder()
PasswordTextField.resignFirstResponder()
}
else
{
// create the alert
let alert = UIAlertController(title: "Incorrect", message: "Your credentials are incorrect.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
Label.text = "The credentials are not correct."
UsernameTextField.resignFirstResponder()
PasswordTextField.resignFirstResponder()
}
}
#IBAction func PressedClickHereSendEmailButton(sender: UIButton)
{
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["nurdin#gmail.com"])
mailComposerVC.setSubject("Sending you an in-app e-mail...")
mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
Here is the AppDelegate class
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
}
Create account page:
import UIKit
var username = ""
var password = ""
var email = ""
class CreateAccountPage: UIViewController
{
#IBOutlet weak var UserNameTextField: UITextField!
#IBOutlet weak var PasswordTextField: UITextField!
#IBOutlet weak var EmailAddressTextField: UITextField!
#IBOutlet weak var ActivateButton: UIButton!
#IBOutlet weak var ReturnButton: UIButton!
#IBAction func PressedActivateButton(sender: UIButton)
{
username = UserNameTextField.text!
password = PasswordTextField.text!
email = EmailAddressTextField.text!
// create the alert
let alert = UIAlertController(title: "Activated", message: "Your new account is now activated.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
}
#IBAction func ReturnButton(sender: UIButton)
{
}
//performSegueWithIdentifier("mySegueID", sender: nil
}
EDIT: I also included two screenshots so please view them to make it clear.
EDIT #2: I would post more screenshots of the storyboard links but I can only post two, so let me know and I'll email them.

The MailCompositionService quit unexpectedly error is a simulator bug. Run your mail sending code on a real device to test it.

This is simulator problem not your problem , Try to connect your iPhone using usb and select it from Xcode then run the application , it should work without error , if there is an errors let us know

Related

Validating user swift 4, login page

I need to my button proceedToAppFeatures to run the code and display an alert of success or failure login(just a single user, for now)
I have tried self.showAlert and self.present
Code:
import UIKit
import FLAnimatedImage
import ImageIO
import UserNotifications//import this to use user notifications
import Firebase
class ViewController: UIViewController, UITextFieldDelegate{
#IBOutlet weak var background: FLAnimatedImageView!
#IBOutlet weak var emailTextField: UITextField!
#IBOutlet weak var passwordTextField: UITextField!
#IBOutlet weak var lblValidationTxt: UILabel!
#IBOutlet weak var lblValidationMessage: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
background.loadGif(name: "neon lights")
passwordTextField.isSecureTextEntry = true// the password will no be visible
emailTextField.delegate = self
passwordTextField.delegate = self
let Tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(DismissKeyboard))//here i have used the function to didmiss the keyboard
view.addGestureRecognizer(Tap)
let center = UNUserNotificationCenter.current()
//this initialize the permission that will appear on user screen
center.requestAuthorization(options: [.alert, .sound, .badge]) {
(granted,error) in
//enable or disable features based on the authorization
}
// emailTextField.text = ""
// passwordTextField.text = ""//on view did load to store text field property
}
#objc func DismissKeyboard() {//function that implements the type outside the screen
view.endEditing(true)
}
#IBAction func sigInButton(_ sender: UIButton) {
performSegue(withIdentifier: "userData", sender: true)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == emailTextField {
textField.resignFirstResponder()
}else{
passwordTextField.becomeFirstResponder()//just to decide which of the buttons will respond after a tab is pressed
passwordTextField.resignFirstResponder()
}
return true
}
func showAlert(title: String, message: String){
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: {(action) in alert.dismiss(animated: true, completion: nil)}))
self.present(alert, animated: true, completion: nil)
}
func isValidEmail(testStr:String) -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailTest = NSPredicate(format:"SELF MATCHES %#", emailRegEx)
return emailTest.evaluate(with: testStr)
}
#IBAction func proceedToAppFeatures(_ sender: Any) {
let email = isValidEmail(testStr: emailTextField.text!)
if email == false{
self.showAlert(title: "ERROR", message: "This is not a valid e-mail. Please try again")
emailTextField.text = ""
}else{
self.showAlert(title: "Success", message: "Yousucessifully loged in")
//performSegue(withIdentifier: "formPage", sender: true)
}
let myEmail: String!
myEmail = emailTextField.text!
let myPassword: String!
myPassword = passwordTextField.text!
if(myEmail == "leandroaaramos" && myPassword == "123456"){
//performSegue(withIdentifier: "homeSegue", sender: nil)
//code for the truth
print("You are success")
}else if (myEmail.isEmpty && myPassword.isEmpty){
//here i put the alert message
let alert = UIAlertController(title: "Wow", message: "Hold on fill the gaps", preferredStyle: UIAlertController.Style.alert)
//add an action to the alert
alert.addAction(UIAlertAction(title: "Close", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
self.showAlert(title: "Empty field", message: "Try again")
}else {
//here i put the alert message
let alert = UIAlertController(title: "Ops", message: "Your account is not here", preferredStyle: UIAlertController.Style.alert)
//add an action to the alert
alert.addAction(UIAlertAction(title: "Try Again", style: UIAlertAction.Style.default, handler: nil))
self.present(alert, animated: true, completion: nil)
self.showAlert(title: "Sorry", message: "Can't find you.")
}
}
}
I want go to my loginViewController, if the user leandroaaramos and password 123456 was typed.

Error - The email address is badly formed. Xcode Swift Firebase

I'm building a UI interface with authentication as an iOS app. I've come a long way from where I was originally but I cannot get past this error. I don't understand what I'm compiling incorrectly. Please take a look and help me out if you can.
import UIKit
import Firebase
class SignUpViewController: UIViewController, UITextFieldDelegate
{
#IBOutlet weak var email: UITextField!
#IBOutlet weak var password: UITextField!
#IBOutlet weak var passwordConfirm: UITextField!
#IBOutlet weak var signUpButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
email.delegate = self
password.delegate = self
passwordConfirm.delegate = self
}
#IBAction func signUpAction(_ sender: UIButton) {
if password.text !=
passwordConfirm.text{
let alertController = UIAlertController(title: "Password Incorrect", message: "Please re-type password", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
else{
Auth.auth().createUser(withEmail: email.text!, password: password.text!){ (user, error) in
if error == nil {
self.performSegue(withIdentifier: "signupToHome", sender: self)
}
else{
let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool { //delegate method
textField.resignFirstResponder()
return true
}
}
The goal is to then accept the user input from email.text and password.text and segue into the home screen after creating a new user in my Firebase console.
Firebase has its own email validation which is like this 'abc#somedomain.com' so you need to pass a email address like this other wise it will keep throwing this error.

Sequre text inside UITextField

The password textfield doesn't hide the password charecters to be dots.
import UIKit
import Firebase
import FirebaseDatabase
class signupViewController: UIViewController {
#IBOutlet weak var email: UITextField!
#IBOutlet weak var password: UITextField!
#IBOutlet weak var signup: UIButton!
#IBOutlet weak var cancel: UIButton!
var databaseref = FIRDatabase.database().reference()
override func viewDidLoad() {
super.viewDidLoad()
signup.enabled = true
}
#IBAction func didtapcancel(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil)
}
#IBAction func didtapsignup(sender: AnyObject) {
signup.enabled=true
FIRAuth.auth()?.createUserWithEmail(email.text!, password: password.text!, completion: {(user,error) in
if error != nil {
if error!.code == 17999 {
let alert = UIAlertController(title: "error 17999", message: "ohh", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
else {
print(error?.localizedDescription)
let alert = UIAlertController(title: "error ", message: "tt", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)}
}
else
{
FIRAuth.auth()?.signInWithEmail(self.email.text!, password: self.password.text!, completion: {(user,error) in
if (error == nil) {
self.databaseref.child("users").child(user!.uid).child("email").setValue(self.email.text!)
self.performSegueWithIdentifier("ahmed", sender: nil)
}
})
}
}
)}
}
The question asks
Sequre text inside UITextField
Select Secure Text Entry for the control on the storyboard.
It's about 1/2 way down in the attributes inspector for that control.
'showing dots' and Firebase are unrelated as that functionality is part of the text field, not Firebase.
There's an additional unrelated question, which should be posted separately, and to address that more information would be needed from the statement
print(error?.localizedDescription)

Swift 3 - Thread 1: Signal SIGABRT

I am attempting to change views in the simulator via a button click but keep getting the error:
Thread 1: signal SIGABRT
I am aware that this usually occurs when there is a disconnect with outlets or actions but I have checked and they all seem to be linked.
AppDelegate.swift
import UIKit
import Parse
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// Parse configuration in Heroku
let configuration = ParseClientConfiguration {
// accessing Heroku App via ID and Keys
$0.applicationId = "truegramIDDB91"
$0.clientKey = "truegramKeyDB91"
$0.server = "http://truegram.herokuapp.com/parse"
}
// call login function
login()
Parse.initialize(with: configuration)
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func login() {
// remember user's login
let username : String? = UserDefaults.standard.string(forKey: "username")
// if logged in
if username != nil {
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let myTabBar = storyboard.instantiateViewController(withIdentifier: "tabBar") as! UITabBarController
window?.rootViewController = myTabBar
}
}
}
SignInVC.swift
import UIKit
import Parse
class signInVC: UIViewController {
// textfields
#IBOutlet weak var usernameTxt: UITextField!
#IBOutlet weak var passwordTxt: UITextField!
#IBOutlet weak var label: UILabel!
// sign in button view
#IBOutlet weak var signinBtnBlock: UIView!
// buttons
#IBOutlet weak var signInBtn: UIButton!
#IBOutlet weak var signUpBtn: UIButton!
#IBOutlet weak var forgotPasswordBtn: UIButton!
// default function
override func viewDidLoad() {
super.viewDidLoad()
// font of label (Clubbr)
label.font = UIFont(name: "gillsans-light", size: 22)
}
// clicked sign in button
#IBAction func signInBtnClick(sender: AnyObject) {
print("sign in pressed")
// hide keyboard
self.view.endEditing(true)
// if text fields are empty
if usernameTxt.text!.isEmpty || passwordTxt.text!.isEmpty {
// show alert message
let alert = UIAlertController(title: "Please", message: "fill in fields", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
// login functions
PFUser.logInWithUsername(inBackground: usernameTxt.text!, password: passwordTxt.text!) { (user: PFUser?, error: Error?) -> Void in
if error == nil {
// remember user or save in app memory (did the user log in or not)
UserDefaults.standard.set(user!.username, forKey: "username")
UserDefaults.standard.synchronize()
// Call login function from AppDelegate.swift class
let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
} else {
// show alert message
let alert = UIAlertController(title: "Error", message: error!.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
SignUpVc.swift
import UIKit
import Parse
class signUpVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// profile image
#IBOutlet weak var avaImg: UIImageView!
// textfields
#IBOutlet weak var firstnameTxt: UITextField!
#IBOutlet weak var lastnameTxt: UITextField!
#IBOutlet weak var emailTxt: UITextField!
#IBOutlet weak var passwordTxt: UITextField!
#IBOutlet weak var confirmTxt: UITextField!
// buttons
#IBOutlet weak var loginBtn: UIButton!
#IBOutlet weak var signupBtn: UIButton!
#IBOutlet weak var businessSignupBtn: UIButton!
// scroll view
#IBOutlet weak var scrollView: UIScrollView!
// resets scroll view to default size
var scrollViewHeight : CGFloat = 0
// keyboard frame size
var keyboard = CGRect()
// default func
override func viewDidLoad() {
super.viewDidLoad()
// check notifications if keyboard is shown or not
NotificationCenter.default.addObserver(self, selector: Selector(("showKeyboard:")), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: Selector(("hideKeyboard:")), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
// declare hide keyboard tap
let hideTap = UITapGestureRecognizer(target: self, action: Selector(("hideKeyboardTap:")))
hideTap.numberOfTapsRequired = 1
self.view.isUserInteractionEnabled = true
self.view.addGestureRecognizer(hideTap)
// profile image circle shape and custom border colour
avaImg.layer.borderWidth = 2
avaImg.layer.borderColor = UIColor.init(red: 90/255, green: 187/255, blue: 181/255, alpha: 1).cgColor
avaImg.layer.cornerRadius = avaImg.frame.height/2
avaImg.clipsToBounds = true
// declare select image tap
let avaTap = UITapGestureRecognizer(target: self, action: Selector(("loadImg:")))
avaTap.numberOfTapsRequired = 1
avaImg.isUserInteractionEnabled = true
avaImg.addGestureRecognizer(avaTap)
}
// call picker to select image
func loadImg(recognizer: UITapGestureRecognizer) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
picker.allowsEditing = true
present(picker, animated: true, completion: nil)
}
// connect selected image to our image view
private func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
avaImg.image = info[UIImagePickerControllerEditedImage] as? UIImage
self.dismiss(animated: true, completion: nil)
}
// hide keyboard if tapped
func hideKeyboardTap(recognizer: UITapGestureRecognizer) {
self.view.endEditing(true)
}
// show keyboard
func showKeyboard(notification: NSNotification) {
// define keyboard sizes
keyboard = ((notification.userInfo?[UIKeyboardFrameEndUserInfoKey]! as AnyObject).cgRectValue)!
//move up UI
UIView.animate(withDuration: 0.4) { () -> Void in
self.scrollView.frame.size.height = self.scrollViewHeight - self.keyboard.height
}
}
// hide keyboard
func hideKeyboard(notification: NSNotification) {
//move down UI
UIView.animate(withDuration: 0.4) { () -> Void in
self.scrollView.frame.size.height = self.view.frame.height
}
}
// clicked sign up
#IBAction func signupBtnClick(sender: AnyObject) {
print("sign up pressed")
// dismiss keyboard
self.view.endEditing(true)
// if fields are empty
if (emailTxt.text!.isEmpty || passwordTxt.text!.isEmpty || confirmTxt.text!.isEmpty || firstnameTxt.text!.isEmpty || lastnameTxt.text!.isEmpty) {
// alert pop up message
let alert = UIAlertController(title: "Please", message: "fill all fields", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
// if incorrect password
if passwordTxt.text != confirmTxt.text {
// alert pop up message
let alert = UIAlertController(title: "Attention", message: "incorrect password", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
// send data to related columns in server
let user = PFUser()
user.username = emailTxt.text?.lowercased()
user.email = emailTxt.text?.lowercased()
user.password = passwordTxt.text
user["firstname"] = firstnameTxt.text?.lowercased()
user["lastname"] = lastnameTxt.text?.lowercased()
// convert our image for sending to server
let avaData = UIImageJPEGRepresentation(avaImg.image!, 0.5)
let avaFile = PFFile(name: "ava.jpg", data: avaData!)
user["ava"] = avaFile
// save data in server
user.signUpInBackground { (success: Bool, error: Error?) -> Void in
if success {
print("registered")
// remember logged user
UserDefaults.standard.set(user.username, forKey: "username")
UserDefaults.standard.synchronize()
// calls login func from AppDelegate.swift class
let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
} else {
// show alert message
let alert = UIAlertController(title: "Error", message: error!.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
}
}
// clicked return to log in
#IBAction func loginBtnClick(sender: AnyObject) {
self.dismiss(animated: true, completion: nil)
// dismiss keyboard
self.view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
ResetPasswordVC.swift
import UIKit
import Parse
class resetPasswordVC: UIViewController {
// text field
#IBOutlet weak var emailTxt: UITextField!
// buttons
#IBOutlet weak var cancelBtn: UIButton!
#IBOutlet weak var resetBtn: UIButton!
// clicked cancel button
#IBAction func cancelBtnClick(sender: AnyObject) {
self.dismiss(animated: true, completion: nil)
// dismiss keyboard
self.view.endEditing(true)
}
// clicked reset button
#IBAction func resetBtnClick(sender: AnyObject) {
// hide keyboard
self.view.endEditing(true)
// if email text field is empty
if emailTxt.text!.isEmpty {
// show alert message
let alert = UIAlertController(title: "Email field", message: "is empty", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
// request for resetting password
PFUser.requestPasswordResetForEmail(inBackground: emailTxt.text!) { (success: Bool, error: Error?) -> Void in
if success {
// show alert message
let alert = UIAlertController(title: "Reset Password Email", message: "has been sent to the email address associated with your account", preferredStyle: UIAlertControllerStyle.alert)
// of ok is pressed call self.dismiss.. function
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (UIAlertAction) -> Void in
self.dismiss(animated: true, completion: nil)
})
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
} else {
print(error?.localizedDescription)
}
}
}
// default func
override func viewDidLoad() {
super.viewDidLoad()
// tap to hide keyboard
let hideTap = UITapGestureRecognizer(target: self, action: Selector(("hideKeyboard:")))
hideTap.numberOfTapsRequired = 1
self.view.isUserInteractionEnabled = true
self.view.addGestureRecognizer(hideTap)
}
// hide keyboard function
func hideKeyboard(recognizer: UITapGestureRecognizer) {
self.view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I am sure the issue is something fairly obvious but I have only been working with Swift for 3 months and it is my first programming language. I would really appreciate the help.
Thanks for your time.
SAME ERROR
Hey guys, I've been trying my best to sort this myself but cannot get to grips with it. After the initial response from #Vadian solved the issue of the IBActions, I have still been receiving the same SIGABRT error.
Error Info
2016-10-06 17:18:33.709206 Truegram[13130:1026640] [MobileAssetError:29] Unable to copy asset information from https://mesu.apple.com/assets/ for asset type com.apple.MobileAsset.TextInput.SpellChecker
sign up pressed
2016-10-06 17:18:53.120 Truegram[13130:1026284] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The class PFUser must be registered with registerSubclass before using Parse.'
I think the above is most relevant to the error and this seems to be vindicated as the error occurs after pressing 'sign up'
I have also added another sign up page, specific to businesses that might be causing the issue.
BusinessSignUp.swift
import UIKit
import Parse
class BusinessSignUpVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// profile image
#IBOutlet weak var BusinessAvaImg: UIImageView!
// textfields
#IBOutlet weak var confirmTxt: UITextField!
#IBOutlet weak var passwordTxt: UITextField!
#IBOutlet weak var AddressTxt: UITextView!
#IBOutlet weak var contactNumTxt: UITextField!
#IBOutlet weak var emailTxt: UITextField!
#IBOutlet weak var businessNameTxt: UITextField!
// buttons
#IBOutlet weak var loginBtn: UIButton!
#IBOutlet weak var signupBtn: UIButton!
#IBAction func loginBtnClick(_ sender: AnyObject) {
}
// keyboard frame size
var keyboard = CGRect()
override func viewDidLoad() {
super.viewDidLoad()
// check notifications if keyboard is shown or not
NotificationCenter.default.addObserver(self, selector: #selector(BusinessSignUpVC.showKeyboard(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: Selector(("hideKeyboard:")), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
// declare hide keyboard tap
let hideTap = UITapGestureRecognizer(target: self, action: #selector(BusinessSignUpVC.hideKeyboardTap(_:)))
hideTap.numberOfTapsRequired = 1
self.view.isUserInteractionEnabled = true
self.view.addGestureRecognizer(hideTap)
// profile image circle shape and custom border colour
BusinessAvaImg.layer.borderWidth = 2
BusinessAvaImg.layer.borderColor = UIColor.init(red: 90/255, green: 187/255, blue: 181/255, alpha: 1).cgColor
BusinessAvaImg.layer.cornerRadius = BusinessAvaImg.frame.height/2
BusinessAvaImg.clipsToBounds = true
// declare select image tap
let avaTap = UITapGestureRecognizer(target: self, action: #selector(BusinessSignUpVC.loadImg(_:)))
avaTap.numberOfTapsRequired = 1
BusinessAvaImg.isUserInteractionEnabled = true
BusinessAvaImg.addGestureRecognizer(avaTap)
}
// call picker to select image
func loadImg(_ recognizer: UITapGestureRecognizer) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
picker.allowsEditing = true
present(picker, animated: true, completion: nil)
}
// connect selected image to our image view
private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
BusinessAvaImg.image = info[UIImagePickerControllerEditedImage] as? UIImage
self.dismiss(animated: true, completion: nil)
}
// hide keyboard if tapped
func hideKeyboardTap(_ recognizer: UITapGestureRecognizer) {
self.view.endEditing(true)
}
// show keyboard
func showKeyboard(_ notification: NSNotification) {
// define keyboard sizes
keyboard = ((notification.userInfo?[UIKeyboardFrameEndUserInfoKey]! as AnyObject).cgRectValue)!
// Do any additional setup after loading the view.
}
// clicked sign up
#IBAction func signupBtnClick(_ sender: AnyObject) {
print("sign up pressed")
// dismiss keyboard
self.view.endEditing(true)
// if fields are empty
if (emailTxt.text!.isEmpty || passwordTxt.text!.isEmpty || confirmTxt.text!.isEmpty || businessNameTxt.text!.isEmpty || AddressTxt.text!.isEmpty || contactNumTxt.text!.isEmpty) {
// alert pop up message
let alert = UIAlertController(title: "Please", message: "fill all fields", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
// if incorrect password
if passwordTxt.text != confirmTxt.text {
// alert pop up message
let alert = UIAlertController(title: "Attention", message: "incorrect password", preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
// send data to related columns in server
let businessUser = PFUser()
businessUser.username = businessNameTxt.text?.lowercased()
businessUser.email = emailTxt.text?.lowercased()
businessUser.password = passwordTxt.text
businessUser["BusinessUser"] = businessNameTxt.text?.lowercased()
businessUser["Address"] = AddressTxt.text?.lowercased()
businessUser["ContactNumber"] = contactNumTxt.text?.lowercased()
// convert our image for sending to server
let avaData = UIImageJPEGRepresentation(BusinessAvaImg.image!, 0.5)
let avaFile = PFFile(name: "ava.jpg", data: avaData!)
businessUser["ava"] = avaFile
// save data in server
businessUser.signUpInBackground { (success: Bool, error: Error?) -> Void in
if success {
print("registered")
// remember logged user
UserDefaults.standard.set(businessUser.username, forKey: "username")
UserDefaults.standard.synchronize()
// calls login func from AppDelegate.swift class
let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
} else {
// show alert message
let alert = UIAlertController(title: "Error", message: error!.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)
let ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alert.addAction(ok)
self.present(alert, animated: true, completion: nil)
}
}
}
// clicked return to log in
#IBAction func businessLoginBtnClick(_ sender: AnyObject) {
self.dismiss(animated: true, completion: nil)
// dismiss keyboard
self.view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
This has now taken me a couple of days attempting to fix, so I would be very appreciative if anyone could help.
The crucial information is
[Truegram.signUpVC signupBtnClick:]: unrecognized selector sent to instance 0x7f9d0700cff0'
In Swift 3 IBActions are supposed to be declared with an underscore to omit the parameter label.
#IBAction func signupBtnClick(_ sender: AnyObject)

Unknown Selector Issue

I am attempting to create a sign up page where people put such info as their email and desired password, after this is completed I want to switch to the next view controller however, I am getting the following error
[StudyBuddy.SignUpViewController signUpButton:]: unrecognized selector sent to instance 0x7fac5e061b80'
SignUpViewController
import UIKit
import Firebase
import CoreData
import CoreLocation
class SignUpViewController: UIViewController {
#IBOutlet weak var emailField: UITextField!
#IBOutlet weak var passwordField: UITextField!
#IBOutlet weak var confirmPasswordField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
if let user = FIRAuth.auth()?.currentUser {
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func signupButton(sender: AnyObject)
{
if self.emailField.text == "" || self.passwordField.text == "" {
let alertController = UIAlertController(title: "Oops!", message: "Please enter a valid username and password", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "Ok", style: .Cancel, handler: nil)
self.presentViewController(alertController, animated: true, completion: nil)
}
else if self.confirmPasswordField.text != self.passwordField.text {
let passwordAlert = UIAlertController(title: "Oops!", message: "Passwords do not match", preferredStyle: .Alert)
let passwordAction = UIAlertAction(title: "Ok", style: .Cancel, handler: nil)
self.presentViewController(passwordAlert, animated: true, completion: nil)
}
else {
FIRAuth.auth()?.createUserWithEmail(emailField.text!, password: passwordField.text!, completion: {(user, error) in
if error == nil {
self.performSegueWithIdentifier("goToSignUp", sender: sender)
}
else {
let createAlert = UIAlertController(title: "There was a problem", message: "There was a problem creating your account, please check the information you provided and try again", preferredStyle: .Alert)
let createAction = UIAlertAction(title: "Ok", style: .Cancel, handler: nil)
self.presentViewController(createAlert, animated: true, completion: nil)
}
})
}
}
You need to change your signupButton method declaration with signUpButton because inside your declaration u is lower latter for up you need to change it with Up because method name and property name are case sensitive or else change to selector with this signupButton one where you are adding target for button.

Resources