Skip to content

Commit

Permalink
FirebaseCore: port to android
Browse files Browse the repository at this point in the history
This adjusts the API usage to account for signature differences on
Android. This is the first step towards setting up the android port.
  • Loading branch information
compnerd committed Apr 2, 2024
1 parent d7edf74 commit 9842cb3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Sources/FirebaseCore/FirebaseApp+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,39 @@
@_exported
import firebase

#if os(Android)
private import FirebaseAndroid
#endif

public typealias FirebaseApp = UnsafeMutablePointer<firebase.App>

extension FirebaseApp {
public static func configure() {
#if os(Android)
_ = firebase.App.Create(SwiftFirebase_GetJavaEnvironment(),
SwiftFirebase_GetActivity())
#else
_ = firebase.App.Create()
#endif
}

public static func configure(options: FirebaseOptions) {
#if os(Android)
_ = firebase.App.Create(options.pointee, SwiftFirebase_GetJavaEnvironment(),
SwiftFirebase_GetActivity())
#else
_ = firebase.App.Create(options.pointee)
#endif
}

public static func configure(name: String, options: FirebaseOptions) {
#if os(Android)
_ = firebase.App.Create(options.pointee, name,
SwiftFirebase_GetJavaEnvironment(),
SwiftFirebase_GetActivity())
#else
_ = firebase.App.Create(options.pointee, name)
#endif
}

public static func app() -> FirebaseApp? {
Expand Down
15 changes: 14 additions & 1 deletion Sources/FirebaseCore/FirebaseOptions+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
@_exported
import firebase

#if os(Android)
private import FirebaseAndroid
#endif

import Foundation

public typealias FirebaseOptions = UnsafeMutablePointer<firebase.AppOptions>
Expand All @@ -27,7 +31,16 @@ extension firebase.AppOptions: CustomDebugStringConvertible {

extension FirebaseOptions {
public static func defaultOptions() -> FirebaseOptions {
guard let options = firebase.AppOptions.LoadDefault(nil) else {
#if os(Android)
let options =
firebase.AppOptions.LoadDefault(nil,
SwiftFirebase_GetJavaEnvironment(),
SwiftFirebase_GetActivity())
#else
let options = firebase.AppOptions.LoadDefault(nil)
#endif

guard let options else {
fatalError("unable to deserialise firebase options")
}
return options
Expand Down

0 comments on commit 9842cb3

Please sign in to comment.