I'm new to Xcode and firebase.
I made this simple email login just to check if it works, but it doesn´t.
Firebase is set to public. And I can read and write data.
Now, when working authentication, do I need to change anything?
It doesn't display any errors, it just doesn't create any users in Firebase.
The code is:
import UIKit
import FirebaseAuth
class LoginViewController: UIViewController {
#IBOutlet weak var Username: UITextField!
#IBOutlet weak var Password: UITextField!
#IBAction func Register(_ sender: UIButton) {
Auth.auth().createUser(withEmail: Username.text!, password: Password.text!) { (User, Error) in
}
}
}
We found the problem.
We thought we could use a username instead of an email, but it needs to be an email.
Related
I am a new to programming, and right now I want to give my users a username and then store it in the firebase real time database. However, every time I run my code it comes up with:
Thread 1: signal SIGABRT
I have checked all of my #IB buttons etc for clashes but there is nothing that I can find. I think I have written code that may be out dated so I am hoping someone can shed some light on my situation and help out!
I think there error is coming from here:
import UIKit
import Firebase
class HandlerViewController: UIViewController {
#IBOutlet weak var username: UITextField!
var user : AnyObject?
var ref = DatabaseReference()
override func viewDidLoad() {
super.viewDidLoad()
self.user = Auth.auth().currentUser
ref = Database.database().reference()
// Do any additional setup after loading the view.
}
#IBAction func joinHaps(_ sender: Any) {
ref.child("Usernames").childByAutoId().setValue(username)
self.performSegue(withIdentifier:"HomeScreenOne", sender: nil)
}
}
In your crash log saying 'InvalidFirebaseData', reason: '(setValue:) Cannot store object of type UITextField at,
In this line your getting error, because setValue can't accept UITextField as input.
Change your code to :
#IBAction func joinHaps(_ sender: Any) {
//username is UITextfield, you can fetch text from it using .text
ref.child("Usernames").childByAutoId().setValue(username.text ?? "")
self.performSegue(withIdentifier:"HomeScreenOne", sender: nil)
}
The use case of the app I am developing is I will have login view at the initial. When user logs in with valid credentials, the user should see another view saying welcome user. I am totally beginner and I don't know much more about xcode. I see the screen navigation from storyboard but I have already done many things in xib.
Here is what I have done
SafariExtensionViewController.swift
import SafariServices
class SafariExtensionViewController: SFSafariExtensionViewController {
#IBOutlet weak var passwordMessage: NSTextField!
#IBOutlet weak var emailMessage: NSTextField!
#IBOutlet weak var message: NSTextField!
#IBOutlet weak var email: NSTextField!
#IBOutlet weak var password: NSSecureTextField!
static let shared = SafariExtensionViewController()
override func viewDidLoad() {
self.preferredContentSize = NSSize(width: 300, height: 250)
message.stringValue = ""
emailMessage.stringValue = ""
passwordMessage.stringValue = ""
}
#IBAction func userLogin(_ sender: Any) {
let providedEmailAddress = email.stringValue
let providedPassword = password.stringValue
let isEmailAddressValid = isValidEmailAddress(emailAddressString: providedEmailAddress)
self.message.stringValue = ""
emailMessage.stringValue = ""
passwordMessage.stringValue = ""
if isEmailAddressValid && providedPassword.count > 0 {
// api call is done here
// when success should show another screen
} else {
emailMessage.textColor = NSColor.red
emailMessage.stringValue = "Invalid Email"
}
}
}
here is the screenshot of xib.
Technology used
swift 4
xcode 9
not IOS its mainly for app extension
UPDATE
I am not using storyboard and also it's not IOS. I am using xib and from macos project I am trying to develop app extension which will be shown in browser as an extension.
A lot of time left from question posted, but it can be helpful for others as me (I'm porting safari legacy extension to safari app extension) and find the way with use of NSTabView with tabless style:
The use is:
Ensure to add NSObject in your storyboard from the Library:
And connect with the tabview from Outlet:
I'm rather newbie in Cocoa and Swift and if anyone knows more beautiful solution for routing, please share it with others!
I am trying to programmatically switch the whole screen to grayscale mode, but the CGDisplayForceToGray function has disappeared in Swift 4(?). Is there another function or method to replicate the CGDisplayForceToGray effect or has Apple deprecated functions of this kind entirely? Thank you.
Edit: For example, the code for Desaturate has a function called CGDisplayForceToGray() which turns the whole screen into grayscale mode, in the same way, that the "Use Grayscale" checkbox in the Accessibility Preferences turns the screen into grayscale. See below (this code is from Desaturate):
import Cocoa
import Carbon
#NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
#IBOutlet weak var statusMenu: NSMenu!
var grayscaleStatus = false;
var preferencesWindow: PreferencesWindow!
// For MASShortcut
let callback = {}
let defaultsKey = "global_shortcut"
#IBOutlet weak var window: NSWindow!
#IBAction func quitAction(sender: AnyObject) {
NSApplication.sharedApplication().terminate(self)
}
#IBAction func toggleAction(sender: AnyObject) {
self.toggleGrayscale()
}
func toggleGrayscale() {
grayscaleStatus = !grayscaleStatus
CGDisplayForceToGray(grayscaleStatus)
}
However, when I tried to use the CGDisplayForceToGray() function myself, I get the Use of unresolved identifier error. My guess is that the CGDisplayForceToGray() function was deleted or isn't functional anymore, but I was wondering if there were other alternatives to this function that don't use AppleScript.
Edit: Resolved.
I would like to save user login (email & password) so whenever they open the app, it is already filled in. I want to use "'SwiftkeychainWrapper'.
How should i go about doing this? Here is my email and password outlets:
#IBOutlet var emailTextfield: UITextField!
#IBOutlet var passwordTextfield: UITextField!
my app needs from the user to log in. okay i connected my app to parse, and in the login view controller i wrote these codes
import UIKit
class SigninPageViewController: UIViewController {
#IBOutlet weak var userNameTextField: UITextField!
#IBOutlet weak var userEmailTextField: UITextField!
#IBOutlet weak var userPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func doneButtonTapped(sender: AnyObject) {
let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;
PFUser.logInWithUsernameInBackground(userEmail, password: userPassword) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
// Login is successful
NSUserDefaults.standardUserDefaults().setBool(true, forKey:"isUserLoggedIn");
NSUserDefaults.standardUserDefaults().synchronize();
self.dismissViewControllerAnimated(true, completion: nil);
} else {
println("Could not find user")
}
}
}
}
the problem is when i tried my app and tried to write the wrong email and the wrong password, the app let me log in without checking if the user is exist or not and without printing line (Could not find user). So the question here is how to let my app check if the user is exist or not, and do not let anonymous users in.
You could establish your own requirements for logging in. If you do a fetch for the user with the email address they entered, you can allow log in only if the email address exists. If it doesn't, just send the user an alert, and don't go through with the login.