Skip to content

Commit 65681eb

Browse files
committed
fix: ios bugs
1 parent 8d4cb8b commit 65681eb

File tree

2 files changed

+47
-45
lines changed

2 files changed

+47
-45
lines changed

packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import FlutterMacOS
1111
import Flutter
1212
#endif
1313

14-
@objc public class FLTFirebaseCorePlugin: FLTFirebasePlugin, FlutterPlugin, FirebaseCoreHostApi, FirebaseAppHostApi {
14+
@objc public class FLTFirebaseCorePlugin: FLTFirebasePluginHelper, FlutterPlugin, FLTFirebasePlugin, FirebaseCoreHostApi, FirebaseAppHostApi {
1515
private var coreInitialized = false
1616
private static var customAuthDomains: [String: String] = [:]
1717

@@ -29,7 +29,7 @@ import Flutter
2929
// Returns a singleton instance of the Firebase Core plugin.
3030
@objc public static func sharedInstance() -> FLTFirebaseCorePlugin {
3131
struct Singleton {
32-
static let instance: FLTFirebaseCorePlugin = {
32+
static let instance: FLTFirebaseCorePlugin = {
3333
let instance = FLTFirebaseCorePlugin()
3434
// Register with the Flutter Firebase plugin registry.
3535
FLTFirebasePluginRegistry.shared.registerFirebasePlugin(instance)
@@ -60,27 +60,27 @@ import Flutter
6060
// MARK: - Helpers
6161

6262
private func optionsFromFIROptions(_ options: FirebaseOptions) -> CoreFirebaseOptions {
63-
let pigeonOptions = CoreFirebaseOptions()
64-
pigeonOptions.apiKey = options.apiKey
65-
pigeonOptions.appId = options.googleAppID
66-
pigeonOptions.messagingSenderId = options.gcmSenderID
67-
pigeonOptions.projectId = options.projectID
68-
pigeonOptions.databaseURL = options.databaseURL
69-
pigeonOptions.storageBucket = options.storageBucket
70-
pigeonOptions.iosBundleId = options.bundleID
71-
pigeonOptions.iosClientId = options.clientID
72-
pigeonOptions.appGroupId = options.appGroupID
73-
return pigeonOptions
63+
return CoreFirebaseOptions(
64+
apiKey: options.apiKey ?? "",
65+
appId: options.googleAppID,
66+
messagingSenderId: options.gcmSenderID,
67+
projectId: options.projectID ?? "",
68+
databaseURL: options.databaseURL,
69+
storageBucket: options.storageBucket,
70+
iosClientId: options.clientID,
71+
iosBundleId: options.bundleID,
72+
appGroupId: options.appGroupID
73+
)
7474
}
7575

7676
private func initializeResponse(from firebaseApp: FirebaseApp) -> CoreInitializeResponse {
77-
let appNameDart = FLTFirebasePlugin.firebaseAppName(fromIosName: firebaseApp.name)
78-
let response = CoreInitializeResponse()
79-
response.name = appNameDart
80-
response.options = optionsFromFIROptions(firebaseApp.options)
81-
response.isAutomaticDataCollectionEnabled = firebaseApp.isDataCollectionDefaultEnabled as NSNumber
82-
response.pluginConstants = FLTFirebasePluginRegistry.shared.pluginConstants(forFIRApp: firebaseApp)
83-
return response
77+
let appNameDart = FLTFirebasePluginHelper.firebaseAppName(fromIosName: firebaseApp.name)
78+
return CoreInitializeResponse(
79+
name: appNameDart,
80+
options: optionsFromFIROptions(firebaseApp.options),
81+
isAutomaticDataCollectionEnabled: firebaseApp.isDataCollectionDefaultEnabled,
82+
pluginConstants: FLTFirebasePluginRegistry.shared.pluginConstants(forFIRApp: firebaseApp)
83+
)
8484
}
8585

8686
// MARK: - FLTFirebasePlugin
@@ -94,11 +94,12 @@ import Flutter
9494
}
9595

9696
@objc public var firebaseLibraryName: String {
97-
return String(cString: LIBRARY_NAME, encoding: .utf8) ?? ""
97+
return "flutter-fire-core"
9898
}
9999

100100
@objc public var firebaseLibraryVersion: String {
101-
return String(cString: LIBRARY_VERSION, encoding: .utf8) ?? ""
101+
// TODO: Get version from Package.swift or build configuration
102+
return "4.2.0"
102103
}
103104

104105
@objc public var flutterChannelName: String {
@@ -108,25 +109,20 @@ import Flutter
108109

109110
// MARK: - API
110111

111-
public func initializeApp(
112+
func initializeApp(
112113
appName: String,
113114
initializeAppRequest: CoreFirebaseOptions,
114115
completion: @escaping (Result<CoreInitializeResponse, Error>) -> Void
115116
) {
116-
let appNameIos = FLTFirebasePlugin.firebaseAppName(fromDartName: appName)
117+
let appNameIos = FLTFirebasePluginHelper.firebaseAppName(fromDartName: appName)
117118

118-
if let existingApp = FLTFirebasePlugin.firebaseApp(named: appName) {
119+
if let existingApp = FLTFirebasePluginHelper.firebaseApp(named: appName) {
119120
completion(.success(initializeResponse(from: existingApp)))
120121
return
121122
}
122123

123-
guard let appId = initializeAppRequest.appId,
124-
let messagingSenderId = initializeAppRequest.messagingSenderId else {
125-
completion(.failure(NSError(domain: "FLTFirebaseCore",
126-
code: -1,
127-
userInfo: [NSLocalizedDescriptionKey: "Missing required options"])))
128-
return
129-
}
124+
let appId = initializeAppRequest.appId
125+
let messagingSenderId = initializeAppRequest.messagingSenderId
130126

131127
let options = FirebaseOptions(googleAppID: appId, gcmSenderID: messagingSenderId)
132128
options.apiKey = initializeAppRequest.apiKey
@@ -167,13 +163,14 @@ import Flutter
167163
}
168164
}
169165

170-
public func initializeCore(completion: @escaping (Result<[CoreInitializeResponse], Error>) -> Void) {
166+
func initializeCore(completion: @escaping (Result<[CoreInitializeResponse], Error>) -> Void) {
171167
let initializeCoreBlock: () -> Void = {
172-
let firebaseApps = FirebaseApp.allApps() ?? [:]
173168
var firebaseAppsArray: [CoreInitializeResponse] = []
174169

175-
for (_, firebaseApp) in firebaseApps {
176-
firebaseAppsArray.append(self.initializeResponse(from: firebaseApp))
170+
if let firebaseApps = FirebaseApp.allApps {
171+
for (_, firebaseApp) in firebaseApps {
172+
firebaseAppsArray.append(self.initializeResponse(from: firebaseApp))
173+
}
177174
}
178175

179176
completion(.success(firebaseAppsArray))
@@ -187,13 +184,18 @@ import Flutter
187184
}
188185
}
189186

190-
public func optionsFromResource(completion: @escaping (Result<CoreFirebaseOptions, Error>) -> Void) {
191-
// Unsupported on iOS/MacOS.
192-
completion(.success(CoreFirebaseOptions()))
187+
func optionsFromResource(completion: @escaping (Result<CoreFirebaseOptions, Error>) -> Void) {
188+
// Unsupported on iOS/MacOS - return empty options with minimal required fields
189+
completion(.success(CoreFirebaseOptions(
190+
apiKey: "",
191+
appId: "",
192+
messagingSenderId: "",
193+
projectId: ""
194+
)))
193195
}
194196

195-
public func delete(appName: String, completion: @escaping (Result<Void, Error>) -> Void) {
196-
guard let firebaseApp = FLTFirebasePlugin.firebaseApp(named: appName) else {
197+
func delete(appName: String, completion: @escaping (Result<Void, Error>) -> Void) {
198+
guard let firebaseApp = FLTFirebasePluginHelper.firebaseApp(named: appName) else {
197199
completion(.success(()))
198200
return
199201
}
@@ -209,18 +211,18 @@ import Flutter
209211
}
210212
}
211213

212-
public func setAutomaticDataCollectionEnabled(
214+
func setAutomaticDataCollectionEnabled(
213215
appName: String,
214216
enabled: Bool,
215217
completion: @escaping (Result<Void, Error>) -> Void
216218
) {
217-
if let firebaseApp = FLTFirebasePlugin.firebaseApp(named: appName) {
219+
if let firebaseApp = FLTFirebasePluginHelper.firebaseApp(named: appName) {
218220
firebaseApp.isDataCollectionDefaultEnabled = enabled
219221
}
220222
completion(.success(()))
221223
}
222224

223-
public func setAutomaticResourceManagementEnabled(
225+
func setAutomaticResourceManagementEnabled(
224226
appName: String,
225227
enabled: Bool,
226228
completion: @escaping (Result<Void, Error>) -> Void

packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public typealias FLTFirebaseMethodCallErrorBlock = (String?, String?, [String: A
6969
}
7070
}
7171

72-
@objc open class FLTFirebasePlugin: NSObject {
72+
@objc open class FLTFirebasePluginHelper: NSObject {
7373
/// Creates a standardized instance of FlutterError using the values returned
7474
/// through FLTFirebaseMethodCallErrorBlock.
7575
///

0 commit comments

Comments
 (0)