APIManager

class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate

Data model that encapsulates recorded audio file information including file URL and display title.

  • The currently authenticated user object containing user credentials and data

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Notification to go back to InitialViewController.

    Declaration

    Swift

    let initialNotification = Notification.Name("PresentInitialViewController")
  • Notification to go to DemoViewController.

    Declaration

    Swift

    let demoNotification    = Notification.Name("PresentDemoViewController")
  • vc

    Reference to the presenting view controller used for displaying alerts and authentication UI - Warning: Must be set before calling authentication methods that present UI

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • ref

    Firebase Realtime Database reference for storing and retrieving user data

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Shared singleton instance of the API manager - Note: Access this property instead of creating new instances

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Creates a new user account with Firebase Authentication using email and password. This method uses the credentials stored in the user property to create a new Firebase account. After successful account creation, it displays a notification prompting the user to sign in and posts a notification to transition back to the initial view controller. - Precondition: The user property must be set with valid uid (email) and pw (password) values - Note: This method clears the user property after the operation completes (success or failure) - Important: Account creation does not automatically sign in the user

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Signs in an existing user with Firebase Authentication using email and password. This method authenticates the user using the credentials stored in the user property. Upon successful sign-in, it loads the user's data from Firebase, displays a success notification, and posts a notification to transition to the demo/main view controller. - Precondition: The user property must be set with valid uid (email) and pw (password) values - Note: This method clears the user property if authentication fails - SeeAlso: createUser() for account creation

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Authenticates a user using Facebook Login SDK and Firebase Authentication. This method initiates the Facebook login flow, requesting email permissions. Upon successful Facebook authentication, it creates Firebase credentials using the Facebook access token and signs the user into Firebase. The user's data is then loaded and a notification is posted to transition to the demo/main view controller. - Note: Requires Facebook Login SDK to be properly configured in Info.plist - Important: The app must be registered with Facebook and have a valid App ID - SeeAlso: googleSignIn() for Google authentication

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Initiates the Google Sign-In authentication flow. This method triggers the Google Sign-In process, which will present the Google authentication UI. The actual authentication handling is done in the delegate methods sign(_:didSignInFor:withError:). - Note: Requires Google Sign-In SDK to be properly configured with a valid GoogleService-Info.plist - Important: The vc property must be set to present the Google Sign-In UI - SeeAlso: sign(_:didSignInFor:withError:) for authentication completion handling

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Dismisses the Google Sign-In view controller. This delegate method is called when Google Sign-In needs to dismiss its authentication UI, typically after the user has completed or cancelled the authentication flow. - Parameters: - signIn: The Google Sign-In instance - viewController: The view controller to dismiss - Note: This is a GIDSignInUIDelegate method

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Dismisses the Google Sign-In view controller. This delegate method is called when Google Sign-In needs to dismiss its authentication UI, typically after the user has completed or cancelled the authentication flow. - Parameters: - signIn: The Google Sign-In instance - viewController: The view controller to dismiss - Note: This is a GIDSignInUIDelegate method

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Dismisses the Google Sign-In view controller. This delegate method is called when Google Sign-In needs to dismiss its authentication UI, typically after the user has completed or cancelled the authentication flow. - Parameters: - signIn: The Google Sign-In instance - viewController: The view controller to dismiss - Note: This is a GIDSignInUIDelegate method

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Dismisses the Google Sign-In view controller. This delegate method is called when Google Sign-In needs to dismiss its authentication UI, typically after the user has completed or cancelled the authentication flow. - Parameters: - signIn: The Google Sign-In instance - viewController: The view controller to dismiss - Note: This is a GIDSignInUIDelegate method

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Saves the current user's data to Firebase Realtime Database. This method persists the user's data array to Firebase using a hashed version of their email address as the database key. The data is stored as an NSArray in the Firebase database for later retrieval. - Precondition: The user property must be set with valid data to save - Note: Uses the hash value of the user's email as the database node identifier - Important: Data is only saved if both user and data properties are non-nil

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Loads the current user's data from Firebase Realtime Database. This method retrieves the user's previously saved data from Firebase using the hashed email address as the database key. The data is loaded asynchronously and stored in the user object's data property. - Precondition: The user property must be set to identify which data to load - Note: Uses a single value event observer to fetch data once - Important: The loaded data is cast to [Float] array format

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Logs out the current user by clearing the user session. This method performs a simple logout by setting the user property to nil, effectively clearing the cached user data and credentials from memory. - Note: This does not sign out from Firebase Auth or social providers - Important: Consider calling Firebase's Auth.auth().signOut() for complete logout

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate
  • Presents a UIAlertController with the specified title, message, and action button. This utility method displays feedback to the user through a standard iOS alert dialog. It's used throughout the authentication flow to show success messages, errors, and other important notifications to the user. - Parameters: - title: The title text displayed at the top of the alert - message: The descriptive message body of the alert - actionTitle: The text for the dismissal button (typically "Ok") - Important: Requires the vc property to be set to a valid UIViewController - Note: The alert is presented with a single default action that dismisses the alert

    Declaration

    Swift

    class APIManager: NSObject, GIDSignInDelegate, GIDSignInUIDelegate