iOS Admob Firebase SDKs with/without cocoapods

2019-07-26 13:32发布

问题:

I was trying to add cocoapods for admob firebase in my iOS app. But pod intsall command took too much time. Now i want to add firebase admob directly without cocoapods.

I have downloaded whole SDK from https://dl.google.com/firebase/sdk/ios/3_5_2/Firebase.zip . It shows several folder with like AdMob Analytics, AppIndexing, Auth,Crash, Database,DynamicLinks, Invites, Messaging, RemoteConfig, Storage.

For cocoapods, we see they import firebase in .h file and add [Firebase configure] method.

What for SDK? Do I need to use only AdMob folder here? do I need to use the whole SDK? How would it need to be implemented?

回答1:

Finally, i figured it out. import firebase is not working anymore. Hope the documentation is not updated properly.

Anyone should directly integrate Firebase to your project. And the documentation is not updated still. There is a issue there. Follow steps for analytics, add your database parameter from the video.

https://www.youtube.com/watch?v=joVi3thZOqc

https://www.youtube.com/watch?v=XIQsQ2injLo

Firebase and Admob for recommend to use cocoapods.

This contains 4 separate steps:

-Link with firebase

-Download GoogleService-Info.plist

– Update cocoapods

– init Firebase in app.

Link with Firebase: This is just creating a connection Firebase with Admob app. From the console top right menu, there is a button to connection with firebase.

Console link : https://console.firebase.google.com/?pli=1

Download plist file : It’s free and just takes a few minutes. When asked for a Bundle ID, enter the Bundle ID from the project you want to use for testing.

Once you have a GoogleService-Info.plist file, save it in the same directory as the rest of the XCODE project source.

Update cocoapods and install pod: Now go to project directory from command terminal.

Run this command, this will install cocoapods

     sudo gem install cocoapods

When cocoapods installation is complete, start adding to your projects with this command.

    pod init

This command will create pod file in projects directory. You can add the rest command from terminal but also can be done by opening the file directly. I have done it for admob my project.

   source ‘https://github.com/CocoaPods/Specs.git’

   # platform :ios, ‘7.0’
   pod 'Firebase', '>= 2.5.0'
   target 'projectname' do
   pod ‘Firebase/Core’
   pod ‘Firebase/AdMob’
   pod ‘Firebase/Database’
   end

Save the file and go to command line again. Now run any of this two command.

 pod install

OR

 pod install –verbose

Second one worked for me. I got some bad file issue with first command. This may take more than 2 hours for the first time. Got solution from this link : cocoapods - 'pod install' takes forever

When this complete, you will get some yellow line that firebase , admob and other necessary framework successfully added to your projects with cocopods.

  1. Init FireBase (Most important step *** ) :

Google changes their framework but did not updated their documentation because the way is not working currently.

You may get some issues still: Check you project settings -> Other Linker Option and set it $(inherited). And Don’t forget to set Build architecture YES

Now you have to import Firbase and work for configuring it.

    @import Firebase, this line is not working anymore. 

So you have, import this like :

 #import <Firebase/Firebase.h>

Now configure you Firebase in didFinishLaunchingWithOptions method using

[FIRApp configure];

This is for analytics. To init Database, follow this link:

  1. Where to add Firebase Database Reference in iOS Obj-C
  2. iOS : Objective-C : Firebase : Is it possible to read the cached data first for any reference?

CLEAN, BUILD AND RUN. Hope everything should works fine. You will see few line in your logs that Firebase has been started configuring projects. Happy Developing !!