Search code examples
iosxcodefirebaseios9firebase-realtime-database

Issue converting old firebase code to latest version


Good Evening,

I'm currently studying iOS development along with Firebase.

I'm having a small issues converting some Firebase code to the latest version of Firebase, Inside my lecture, the tutor has set his project up like so:

import Foundation
import Firebase

class DataService {

   static let ds = DataService()

   private var _REF_BASE = Firebase (url: "MyURL")

   var REF_BASE: Firebase {
       return _REF_BASE
   }

}

Then inside the ViewController he has the following:

DataService.ds.REF_BASE.authWithOAuthProvider("facebook", Token: accessToken, withCompletionBlock: { error, authData in 


})

I'm currently using the latest version of Firebase my code is some what different as shown here:

import Foundation
import Firebase

class DataService {

static let ds = DataService()

private var _REF_BASE = FIRDatabase.database().reference()

var ref: FIRDatabase {

    return _REF_BASE

}
}

First issue I have is on return _REF_BASE it says:

Cannot convert return expression of type 'FIRDatabaseReference' to return type FIRDatabase

Next inside my ViewController I have the following:

DataService.ds.ref.authWithOAuthProvider("facebook", Token: accessToken, withCompletionBlock: { error, authData in


 })

However the error I've receiving is:

value of type FIRDatabase has no member authWithOAuthProvider

I have asked the teacher is he has updated code for this lecture however it's been a few days and I can only assume he does not.

Now I'm completely new to Firebase and getting it integrated within IOS so if someone could share their knowledge on how I go about converting the code provided in the lecture to the latest version of Firebase I'd highly appreciate it.

Update

I've been browsing the web trying to find a solution for this, I have tried searching for information on the given answer provided below however I'm unable to find any ideal solution, can anyone suggest any other ideas on how I go about converting the old firebase to the new one?


Solution

  • First issue is of type .. FIRDatabase should be FIRDatabaseReference

      var ref: FIRDatabaseReference { return _REF_BASE }
    

    For FB authentication, method is changed completely ... Full guide here

    let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
    
    FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
        // ...
    }
    

    And to check user exists in database or not check this answer