0

I am trying to create my first app, unfortunately everyone remembers their first piece of code with a new language, and needless to say, it has been a hassle and a half. Right now, I am using a downloaded test file to feel out how things workout with implementing Firebase with swift. Currently, I don't much care about anything besides getting the App to log the email and pass when creating a user into the database.

I have double and triple checked the GoogleService-Info.plist to make sure the correct API key is there. I have downloaded the Google file numerous times after checking that the bundle ID and all other information is correct. The App loads and runs, lets me input an email and a password and as soon as I hit the button to register it throws the Invalid API error. This is what my podfile looks like

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'FirebaseTutorial' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

# Pods for FirebaseTutorial
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
end

This is the function code for the Registration.

@IBAction func createAccountAction(_ sender: AnyObject) {

    if emailTextField.text == "" {
        let alertController = UIAlertController(title: "Error", message: "Please enter your email and password", preferredStyle: .alert)

        let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
        alertController.addAction(defaultAction)

        present(alertController, animated: true, completion: nil)

    } else {
        FIRAuth.auth()?.createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in

            if error == nil {
                print("You have successfully signed up")
                //Goes to the Setup page which lets the user take a photo for their profile picture and also chose a username

                let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
                self.present(vc!, animated: true, completion: nil)

            } 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)
            }
        }
    }
}}

This is the code in the AppDelegate.swift

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FIRApp.configure()

    return true
}

Let me know if there's anything else I can provide in order to get some help with this. I feel pretty desperate every google search and search on here led me to create an account and ask this question. Everyone has to start somewhere right?

Grimthorr
  • 6,856
  • 5
  • 41
  • 53
  • You need to include your error log around your "API ERROR" for us to even be able to help you in the right direction. EDIT: Have you configured SSL on your API Server? If not, iOS Might just simply block your HTTP connection since it is not secure. Then you need to add it to the PLIST to avoid it getting blocked, http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http –  Jan 29 '17 at 01:49
  • Ok, lets see if this is what you are looking for... I feel super novice but this is what I get in the debugger window (I think that's what it is) `2017-01-28 23:03:37.842285 FirebaseTutorial[89583:2934913] [MobileAssetError:29] Unable to copy asset information from https://mesu.apple.com/assets/ for asset type com.apple.MobileAsset.TextInput.SpellChecker` I believe the SSL on the API Server is configured. If I'm assuming correctly that means that the API Key itself is secured to only be accessed by the iOS app with the bundle ID of my app. I feel pretty lost. @Sneak – Stefan Froloshki Jan 29 '17 at 04:11
  • This is the exact issue as this : http://stackoverflow.com/questions/39518796/getting-firebase-mobileasseterror-warning-in-xcode-8 , check for the solution. however, I'm not sure if this is whats causing your connection errors. You need to print out the exact error messages you get from the actual connection to the API. Print Your server response after you click the "submit" button to post your textfield stuff to the server. –  Jan 29 '17 at 04:15
  • I know my XCode and pods are up to date, they were both installed less than 24 hours ago, but I ran updates just to be sure. Would you be able to point me in the direction of how I can print exact error messages like that, as well as where I could possibly find the server response... if it even reaches the server. On the Realtime Database chart, Firebase does register some KBs hit it over the last few hours working on this but I don't know if that means it's from the Simulator or something unrelated @Sneak – Stefan Froloshki Jan 29 '17 at 04:41
  • I am not familiar with neither firebase or Swift, however, try print out the ERROR in (user, error) method you are calling. You are firing an alert with error message, what does the message say? –  Jan 29 '17 at 04:45
  • What simulator is selected in Xcode? I would suggest building a Firebase project from scratch and see if it works. Create a new project, save and quit Xcode then follow the steps here [Add Firebase](https://firebase.google.com/docs/ios/setup). More than likely the issue is with the settings in the downloaded project and it may take some time to track down the issue. Need to eliminate that as a variable so try a new project. – Jay Jan 29 '17 at 15:27

0 Answers0