How to add Firebase to Today Extension iOS
You have to treat the today extension as its own separate app(somewhat)
in your firebase project dashboard, you need to hit the "Add another app" button.
select iOS and then enter the BUNDLE ID of your TODAY EXTENSION
Complete the wizard and download the generated GoogleService-Info.plist file
Add the plist file to your Today Extension's root folder
go to your xcode project, and manually add FirebaseCore.framework and FirebaseDatabase.framework to your Today Extension
finally inside your today today viewcontroller call FirebaseApp.configure()
import FirebaseDatabase
import FirebaseCore
override func viewDidLoad() {
super.viewDidLoad()
FirebaseApp.configure()
}
Can FirebaseAuth 5.0.x be used in an iOS app extension?
Update:
Firebase confirms that a fix is targeted for 5.2.x version. Track the Github issue for latest updates.
It seems as Firebase is not officially supporting extensions in iOS. I have got that info from this GitHub issue (see paulb777's answer). Maybe someone from Firebase can also confirm this here. I am very surprised that we can't use Firebase SDK when creating extensions such as a Today widget.
The only workaround I had was reverting back to an earlier version of Firebase via:
pod 'Firebase', '4.9.0'
This uses the 4.9.0 version of the Firebase SDK and doesn't create compiler errors.
Firebase currentUser returns nil in iOS Today Extension while user is logged in
I'm faced with the same problem. Currently I dealt with it by copying the data contained in Keychain. This works, but I cannot say this is a valid solution.
https://gist.github.com/hhyyg/c1481853bcac27a678f707c0d1afd0f4
User not signed into Firebase in Share App Extension
To expand on KutakMir's answer, these steps worked for us:
Step 1. Set up Firebase for the share extension
Steps from this Stackoverflow answer:
- Copy the containing app's GoogleService-Info.plist into your
extension in Xcode - Drag the copied GoogleService-Info.plist into
Xcode into your share extension and - Change the BUNDLE_ID to the name of your share extension's target
- Add new target to your Podfile
- Install dependencies (
pod install
) - Configure the Firebase
application object in your extension
Step 2. Set up shared container between containing (i.e., main) app and shared extension
Described in App Extension Programming Guide: Handling Common Scenarios. Basically turn on "App Groups" at the Capabilities tab for both your targets (i.e., containing app and share extension), and provide the same designation at both places.
Step 3. Set up keychain sharing
The basic steps are similar to step 2: turn on "Keychain Sharing" at the Capabilities tab for both targets, and provide the designation at both places. (In more detail in the official docs.)
Make sure to append your APP_ID to the Keychain access group when using the queries in the docs! The link above points this out, but
this Github issue comment is more useful.
Step 4. Use the Keychain and shared container to synchronize user access
Our workflow:
On login (either in share extension or main app), save user ID to the shared container, and save username and password to the Keychain using the user ID as the key
On startup (either share extension or main app), check shared container for user ID. If there, it means that user already signed in either the main app or the share extension therefore they should be signed into both. So retrieve credentials from Keychain, and sign in user using
signIn(withEmail:password:completion:)
Our project at the point when everything was set up. It is messy with lots of duplication, but works. Relevant files are
- Access News/LoginViewController.swift
- Access News/SessionStartViewController.swift
- Access News/NVC.swift
- Access-News-Uploader/UploaderNavigationViewController.swift
Tracking down Keychain error codes
This was the most frustrating part. The error codes are of type OSStatus
, and they are listed in Security Framework Result Codes, but sometimes one just sees a signed integer when testing. I couldn't find an official list, but OSStatus.com will save a lot of frustration. For example, here's a query of all the Security Framework codes.
Other useful links to official Keychain docs:
- Adding a Password to the Keychain
- Searching for Keychain Items
- Updating and Deleting Keychain Items
kSecValueData
(it wasn't where I expected it to be)- Item Return Result Keys
- Item Class Keys and Values
- Item Attribute Keys and Values
Related Topics
How to Access the Accelerometer from the Apple Watch
How to Get MAC Address from Cbperipheral and Cbcenter
What Does $0 Represent in Closures in Swift
How to Add a Custom Separator to Uitableviewcell
Swift: How to Draw Shapes and Detect Whether They Intersect
Animation Blocks Resets to Original Position After Updating Text
Which Phassetcollection to Use for Saving an Image
iOS App Getting Throttled from Local Searches
Programmatically Creating Uinavigationcontroller in iOS
Undefined Symbols for Architecture Armv7 for Cocoapods Libraries
Map Url Parameters to Objects Using Restkit
iOS Library to Convert Powerpoint Presentations into Images
Programmatically Determine Current Target (Run or Test) in iOS Project