Firebase Tutorial: Real-time Chat

OMG me too, please help

Hello There! I was wondering if this tutorials handles notifications when I receive a message.

How does this work ? Iā€™ve been searching for that and I cant get my answers so far from Chat tutorials.

Gives error [Use of undeclared type ā€˜Firebaseā€™]
At starting of LoginViewController.swift
How to solve it?

Iā€™m having same error.
Do uā€™ve any solution for it?

I was spending ages figuring this problem out. I had to transition to the new site which is firebase,google.com. For me following the instructions made the app work what applemax wrote down and the link he mentioned.

  1. I went to console.firebase.google.com. Here I saw my old projects which were on firebase.com
  2. I imported these old projects into the new platform. Be careful though! Firebase says: ā€œNote: Youā€™ll no longer be able to manage your project using the firebase.com dashboardā€.
  3. You then click on your project, then you will be taken to a site where you can add an app. You get an option to choose from iOS, Android or Web.
  4. You enter the bundle identifier of your app, then you will get a config file, called GoogleService-Info.plist
  5. Then you install the pods applemax suggested.
  6. You go to AppDelegate and import ā€˜Firebaseā€™ and in didFinishLaunchingWithOptions you put FIRApp.configure()

This worked for me, hopefully it will be useful for you too!

Good luck!

Hi was creating a chat app following this tutorial, I have a problem with displaying the received message. The received message takes long time to appear on the view and the error message ā€œThis application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future releaseā€ appears every time. Kindly help how to go about this.

In my project I used FIRAuth. Here is my pod file:

_# Uncomment this line to define a global platform for your project
platform :ios, ā€˜9.3ā€™
# Uncomment this line if youā€™re using Swift
use_frameworks!

target ā€˜MyAppā€™ do

podā€™Firebaseā€™
pod ā€˜Firebase/Authā€™

end

Hi All,

Here is Objective C project updated to Firebase 3.2.0 and FirebaseDatabase 3.0.1.

Question submitted via support desk by Kimiebi:

How can I implement the user initials, adding images and message click features in swift? It appears at present that their documentation is only in objective-c.

How can I add these features in a swift app? Is there an opportunity for pair programming?

I would love to see this in old objective-c

Good tutorial, although needs updating to the Firebase 3 xx.

But sometimes I think the tutorials (in general on this site) instead of implementing things like a Chat example would be better first sticking to basic principles, and then going on to show real life examples with all the additional code which can muddy the waters a bit.

For instance, a simple login / Auth ViewController which connects to a data display view controller with live updates to the data on the ViewController and the Firebase database. I have been finding the multi-user aspect of the Firebase database somewhat confusing. :slight_smile:

I found it didnā€™t work any more due to the Firebase api version too old. I completed this tutorial
with the newest Firebase api version 3.6.x and swift 3.x.x.

If I run this now, I run into a Ruby issue: About to give up Ā· Issue #5415 Ā· CocoaPods/CocoaPods Ā· GitHub

Here is the fix if you use rvm:

$ rvm reinstall ruby-2.2.2
$ rvm --default use ruby-2.2.2
$ gem install cocoapods
$ pod install

I got it working in Swift 3.0 like that:

class LoginViewController: UIViewController {

var ref: FIRAuth!

override func viewDidLoad() {
    super.viewDidLoad()
    ref = FIRAuth.auth()
}



@IBAction func touchedLogin(_ sender: AnyObject) {
    ref.signInAnonymously(completion: {(user,Error) in
        if Error != nil { print (Error!.localizedDescription); return}
    print(self.ref.currentUser?.displayName)
    self.performSegue(withIdentifier: "LoginToChat", sender: self)
    })
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    super.prepare(for: segue, sender: sender)
 
    let chatVc = segue.destination as! ChatViewController
    
    chatVc.senderId = ref.currentUser?.uid
    chatVc.senderDisplayName = "Some User"
    
}

}
class ChatViewController: JSQMessagesViewController {

var messages = [JSQMessage]()
let rootRef = FIRDatabase.database().reference(fromURL: "yourfirebasedatabasehttphere")
var messageRef: FIRDatabaseReference!


    override func viewDidLoad() {
        super.viewDidLoad()
        title = "ChatChat"
        messageRef = rootRef.child("messages")
    }


override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
}

override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
}      

override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageDataForItemAt indexPath: IndexPath!) -> JSQMessageData! {
    return messages[indexPath.item]
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return messages.count
}

override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) {
    let itemRef = messageRef.childByAutoId()
    let messageItem:Dictionary<String, Any>? = ["text": text, "senderId": senderId]
    itemRef.setValue(messageItem)
    JSQSystemSoundPlayer.jsq_playMessageSentSound()
    finishSendingMessage()
}
}`

Hello, I know this tutorial is older, I just wanted to see if anyone would know why the send button would no longer work. When I push it the didPressSend is not even being called. I put print statements in the method to see if it was and its not. It was working the night before. The only other thing I added was the Nav Bar with the Back button at the top but that should not have affected the Send button at the bottom. I removed it just to make sure but the send button still does not work. When I run it in simulator I see the send button on the bottom right as it is supposed to be but nothing happens when I click it. Thanks for any help.

This tutorial is more than six months old, so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]