Error setting up Firebase in Xcode - ios

I have tried to set up Firebase to work on Xcode using both the quick setup instructions and the manual alternate instructions on Firebase website.
When I used CocoaPods and followed the instructions on the quick setup page, I was able to import Firebase, but I was not able to reference Firebase inside the class. I got the error: Cannot call value of non-function type 'module' xcode
When I tried to set it up manually, I was not able to import or reference Fire base and I got the error: No such module 'Firebase'

I had the same issue when updating my project to the new version of Firebase. A TON of changes were announced at Google I/O and thus there is a good amount of updating to be done.
It sounds like you might be using the old version of Firebase with the new SDK. You should do everything with Firebase 3.0. Hence var rootRef = Firebase(url:"https://<YOUR-FIREBASE-APP>.firebaseio.com") will now be var rootRef = FIRDatabase.database().reference().
Take a look at the setup guide at: https://firebase.google.com/docs/ios/setup#prerequisites (be sure you aren't looking at the legacy docs!). If you want to convert code from the old version of Firebase to 3.0, check out the Upgrading tutorial: https://firebase.google.com/support/guides/firebase-ios#get_a_database_reference_numbered

You should try to manually edit your podfile to something like:
use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Auth'
I use these directives to get it working with Xcode 7.3.

Related

Firebase error even if I don't use it

In my objective-c application, I added Google Analytics using Pods (this is how I add it: pod 'Google/Analytics'). In the Pods folder, I found those Firebase packages FirebaseAnalytics, FirebaseCore and the FirebaseInstanceId). When I run my application, sometimes it crash and this is what I'm getting in the console:
[Firebase/Core][I-COR000003] The default Firebase app has not
yet been configured. Add [FIRApp configure] to your application
initialization.
I don't call the Firebase classes anymore and I don't want to use them.
Why am I having Firebase even if I didn't add them? Why am I having this error? How can I resolve this? If I delete the packages will that cause a problem?
Google Analytics is not recommended anymore for mobile applications:
The Firebase SDK is the recommended method to track iOS apps.
And AFAIK, the development of the features + pod maintenance is not a priority as they fully shifted towards Firebase.
I know some legacy code has to remain on GA because of outstanding history of logs. But if you have a fresh app, I strongly recommend doing analytics with Firebase.
The Google pod depends on Firebase. Change your Podfile to directly depend upon GoogleAnalytics without the slash.
pod 'GoogleAnalytics'

Can't find Firebase's PhoneAuthProvider class

I'm working on adding a phone authentication login to my app, but my xcode just can't find the PhoneAuthProvider class. I have included
import Firebase
import FirebaseAuth
and the right pods installed
pod ‘Firebase/Auth’
pod ‘Firebase/Database’
pod ‘Firebase/Core’
Any idea to why it's not available for me?
Apparently it was because my Firebase pods were outdated, after updating them to the newest version I was able to use the class.
To update your Firebase pods, go to terminal and type in
pod update Firebase/Auth
I'm gonna leave it here as I've found a few similar questions without any answers.
It's a problem in creation or config project or app. You need just need go:
project-> add another app
and redo all process that you can create app.
In my case that worked.
Note: don't create another project because Firebase only provide 3 project to create.
You need to go to Project> Clean Build Folder. Build the project. This fixes my problem.
In my case I had to close whole XCode and then open it again, and everything worked fine.

I updated the cocoapods for Firebase and my app display error messages now

I have some code lines that doesn't work anymore since I updated the Firebase with cocoapods.
For that examples, I give the error message :
override init() {
Firebase.defaultConfig().persistenceEnabled = true
}
=> Cannot call value of non-function type 'module'<'Firebase>'
That other line:
let rootRef = Firebase(url: "https://<mysite>.firebaseio.com/")
var messageRef: Firebase!
=> Cannot call value of non-function type 'module'<'Firebase>''
messagesQuery.observeEventType(.ChildAdded) { (snapshot: FDataSnapshot!) in
=> Use of undeclared type 'FDataSnapshot'
It seems that Firebase doesn't work anymore that way...
This is how you do it in the "new" Firebase.
First
override init() {
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
FIRApp.configure()
}
Second
let databaseRef = FIRDatabase.database().reference()
// To get a child use .child(childName)
Third
databaseRef.observeSingleEventOfType(.ChildAdded, withBlock: {
snapshot in
print(snapshot.value!)
})
1) Look this tutorial. This guy explanes very well how to install firebase with cocoapods:
Swift: Firebase 3 - Installing SDK using Cocoapods and Saving Users into Database
2) Otherwise you can follow this step by step guide on the official page if you want to try to put firebase again:
Add Firebase to your iOS Project
Add Firebase to your app
It's time to add Firebase to your app. To do this you'll need a Firebase project and a Firebase configuration file for your app.
Create a Firebase project in the Firebase console, if you don't already have one. If you already have an existing Google project associated with your mobile app, click Import Google Project. Otherwise, click Create New Project.
Click Add Firebase to your iOS app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file.
When prompted, enter your app's bundle ID. It's important to enter the bundle ID your app is using; this can only be set when you add an app to your Firebase project.
At the end, you'll download a GoogleService-Info.plist file. You can download this file again at any time.
If you haven't done so already, copy this into your Xcode project root.
Note: If you have multiple build variants with different bundle IDs defined, each app must be added to your project in Firebase console.
Add the SDK
If you are setting up a new project, you need to install the SDK. You may have already completed this as part of creating a Firebase project.
We recommend using CocoaPods to install the libraries. You can install Cocoapods by following the installation instructions. If you'd rather not use CocoaPods, you can integrate the SDK frameworks directly by following the instructions below.
If you are planning to download and run one of the quickstart samples the Xcode project and Podfile are already present. If you would like to integrate the Firebase libraries into one of your own projects, you will need to install the pods for the libraries that you want to use.
If you don't have an Xcode project yet, create one now.
Create a Podfile if you don't have one:
$ cd your-project directory
$ pod init
Add the pods that you want to install. You can include a Pod in your Podfile like this:
pod 'Firebase/Core'
This will add the prerequisite libraries needed to get Firebase up and running in your iOS app, along with Firebase Analytics. A list of currently available pods and subspecs is provided below. These are linked in feature specific setup guides as well.
Install the pods and open the .xcworkspace file to see the project in Xcode.
$ pod install
$ open your-project.xcworkspace
Download a GoogleService-Info.plist file from Firebase console and include it in your app.
3) If you want to upgrade your existing app from Firebase.com:
Upgrade your iOS app from Firebase.com

iOS - Duplicate symbols when added Firebase Messaging (conflict with Google Analytics)

I want to add Firebase Cloud Messaging to my project which has already other services from Google (like Analytics). I am using cocoapods and I added to my podfile:
pod 'Firebase'
pod 'Firebase/Messaging'
I run pod install and everything looked good but when I am trying to build project I get many duplicate symbol errors:
duplicate symbol _OBJC_CLASS_$_ACPGmpAudienceRoot in:
.../Pods/Google/Libraries/libGGLCore.a(GmpAudience.pb.o)
.../Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/FirebaseAnalytics(GmpAudience.pb_d68254ec585824fa42de6de2f056cda0.o)
... more and more duplicate symbol errors ...
How can I fix it? Why with Messaging there is added Analytics library too? I don't need it. I tried Clean project and delete Derived data but for now without luck.
Update your Google/(Google analytics) pod version to 3.0 higher .
I was using version 2.0.4, I did pod update and the following pods were update:
Installing Google 3.0.3 (was 2.0.4)
Installing GoogleSignIn 4.0.0 (was 3.0.0)
After that I was able to use Google analytics with Firebase
Depending on your use case, one thing you can consider: If you use Google Tag Manager, you can integrate with Firebase Analytics, and use GTM to forward the event data to Google Analytics if you prefer to have app and web data together or want to use Google Analytics for some other reason.
I have exactly the same issue - an iOS app that is already using Google Analytics, but I want to add Firebase Messaging, just so the app can have a push notification capability. I added "pod 'Firebase/Messaging'" to the Podfile, and had the same linking errors on compiling.
A lot of searching revealed this compiler setting: Your Target -> Build Settings - Apple LLVM 7.1 - Code Generation -> No Common Blocks - set it to 'Yes', like this:
On Xcode 7.3 it seems the default for that setting is 'No', bu on making that change all the linking errors went away and the app built without issues.

Firebase cannot find 'module <Firebase>'

I'm trying to reference my Firebase class but it's saying I can't find the module...This is strange because everything else in my Firebase is working like:
FIRAuth.auth()?.createUserWithEmail
is working no problem and signing in works too
but when I'm trying to do
let firebase = Firebase(url: "url.com")
I get my module not found problem...
I'm fairly certain I installed it correctly and I tried to follow the advice that people have posted on here already but I'm either doing it wrong or can't figure it out. This is what my build phases looks like.
If you want to use old firebase, use Firebase sdk 2.5.0.
If you are using cocoapods:
pod 'Firebase', '>= 2.5.0'
This will fix your problem and you wont need google service plist
This is just if you want to use the old one. Using new sdk will solve your problem as well.
Firebase has been updated to firebase 3 recently. In firebase 3, the information to your firebase url is provided in GoogleService-Info.plist. you just have to download it from your firebase console and put in your folders
more information can be found here https://firebase.google.com/docs/ios/setup#add_firebase_to_your_app
FireBase(url:) is depreciated.replace with the below code for swift 3
let dataBaseReference = FIRDatabase.database().reference().child("child name").child(subchildname)

Resources