I need to be able to use Firebase in my Today View Extension, however I cannot seem to import the Firebase module. I think it's because I need a new target in my cocoa pods file, but I'm not sure on how to do this.
Thanks.
Or without adding an extra app at the Firebase console, just re-use your main project's GoogleService-Info.plist
with a minor modification (see below). The Firebase app singleton would have to be configured either way in both apps on startup.
To synchronize an extension and the containing app see App Extension Programming Guide: Handling Common Scenarios or this reddit comment. This Stackoverflow thread specifically describes this scenario.
Steps:
GoogleService-Info.plist
into your extension in XcodeGoogleService-Info.plist
into Xcode into your share extension andPodfile
pod install
)GoogleService-Info.plist
into your extension in XcodeGoogleService-Info.plist
into Xcode into your share extension andFor us the main (i.e., containing app) is Access News
and the share extension is Access-News-Uploader
.
Podfile
# ...
target 'name-of-your-extension' do
use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Auth'
# etc.
end
Entire Podfile
of our project.
pod install
)/* 1. Import Firebase */
/**********************/
import Firebase
/**********************/
class WhereverInYourExtension: WhateverController {
// ...
override func viewDidLoad() {
super.viewDidLoad()
/* 2. Configure Firebase */
/*************************/
if FirebaseApp.app() == nil {
FirebaseApp.configure()
}
/*************************/
// ...
}
1) Still unable to import Firebase!
Make sure that pods are installed for all targets in your project. To achieve this use inherit!
or abstract_target
in your Podfile.
The simplest example using abstract_target
from the official documentation:
abstract_target 'Networking' do
pod 'AlamoFire'
target 'Networking App 1'
target 'Networking App 2'
end
For inherit!
, see this SO question and answer.
2) How do I achieve this on my existing app without messing things up?
Remove Podfile
, Podfile.lock
and YourProject.xcworkspace
Issue pod init
and it will list your existing targets one by one.
Edit the Podfile
by either grouping under abstract_target
or using inherit!
Issue pod install
A new YourProject.xcworkspace
file will be generated, and if you open the your project using this, under General
> Linked Frameworks and Libraries
it will show that Firebase is added and can be imported from project files.
(See this SO thread for a concrete example where this clean-up method needed to be used.)
3)
firebase 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
This is what worked for me:
wiped everything clean by cloning our project repo fresh from Github,
deleted
Issue pod init
on the console
Recreate Podfile
(basically copy-paste)
Issue pod update
on the console
(Probably won't work next time.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With