diff --git a/Package.swift b/Package.swift index 15cbae486048..a6f8b1e590bd 100644 --- a/Package.swift +++ b/Package.swift @@ -36,13 +36,7 @@ let package = Package( dependencies: [ .product(name: "FirebaseInstallations", package: "firebase-ios-sdk"), ], - path: "Sources/firebase_core_shared", - publicHeadersPath: "include", - cSettings: [ - .headerSearchPath("include/firebase_core"), - .define("LIBRARY_VERSION", to: "\"\(firebase_core_version)\""), - .define("LIBRARY_NAME", to: "\"flutter-fire-core\""), - ] + path: "packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core" ), ] ) diff --git a/Sources/firebase_core_shared/FLTFirebaseCorePlugin.m b/Sources/firebase_core_shared/FLTFirebaseCorePlugin.m deleted file mode 120000 index e94afa3aad20..000000000000 --- a/Sources/firebase_core_shared/FLTFirebaseCorePlugin.m +++ /dev/null @@ -1 +0,0 @@ -../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m \ No newline at end of file diff --git a/Sources/firebase_core_shared/FLTFirebasePlugin.m b/Sources/firebase_core_shared/FLTFirebasePlugin.m deleted file mode 120000 index 76c49e1d4542..000000000000 --- a/Sources/firebase_core_shared/FLTFirebasePlugin.m +++ /dev/null @@ -1 +0,0 @@ -../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m \ No newline at end of file diff --git a/Sources/firebase_core_shared/FLTFirebasePluginRegistry.m b/Sources/firebase_core_shared/FLTFirebasePluginRegistry.m deleted file mode 120000 index be294affaf60..000000000000 --- a/Sources/firebase_core_shared/FLTFirebasePluginRegistry.m +++ /dev/null @@ -1 +0,0 @@ -../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/FLTFirebaseCorePlugin.h b/Sources/firebase_core_shared/include/FLTFirebaseCorePlugin.h deleted file mode 120000 index 8e3a8c248b88..000000000000 --- a/Sources/firebase_core_shared/include/FLTFirebaseCorePlugin.h +++ /dev/null @@ -1 +0,0 @@ -../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/FLTFirebasePlugin.h b/Sources/firebase_core_shared/include/FLTFirebasePlugin.h deleted file mode 120000 index 6bbe0e68429a..000000000000 --- a/Sources/firebase_core_shared/include/FLTFirebasePlugin.h +++ /dev/null @@ -1 +0,0 @@ -../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/FLTFirebasePluginRegistry.h b/Sources/firebase_core_shared/include/FLTFirebasePluginRegistry.h deleted file mode 120000 index e0b26a14c24f..000000000000 --- a/Sources/firebase_core_shared/include/FLTFirebasePluginRegistry.h +++ /dev/null @@ -1 +0,0 @@ -../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h \ No newline at end of file diff --git a/Sources/firebase_core_shared/include/messages.g.h b/Sources/firebase_core_shared/include/messages.g.h deleted file mode 120000 index 3a5ff91b8660..000000000000 --- a/Sources/firebase_core_shared/include/messages.g.h +++ /dev/null @@ -1 +0,0 @@ -../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h \ No newline at end of file diff --git a/Sources/firebase_core_shared/messages.g.m b/Sources/firebase_core_shared/messages.g.m deleted file mode 120000 index 9b2e6e36e348..000000000000 --- a/Sources/firebase_core_shared/messages.g.m +++ /dev/null @@ -1 +0,0 @@ -../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m \ No newline at end of file diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTDocumentSnapshotStreamHandler.m b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTDocumentSnapshotStreamHandler.m index a787f8ad92b9..386a86f4bdd3 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTDocumentSnapshotStreamHandler.m +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTDocumentSnapshotStreamHandler.m @@ -3,11 +3,7 @@ // found in the LICENSE file. @import FirebaseFirestore; -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; #import "include/cloud_firestore/Private/FLTDocumentSnapshotStreamHandler.h" #import "include/cloud_firestore/Private/FLTFirebaseFirestoreUtils.h" @@ -48,10 +44,10 @@ - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments @"message" : message, }; dispatch_async(dispatch_get_main_queue(), ^{ - events([FLTFirebasePlugin createFlutterErrorFromCode:code - message:message - optionalDetails:details - andOptionalNSError:error]); + events([FLTFirebasePluginHelper createFlutterErrorWithCode:code + message:message + optionalDetails:details + andOptionalError:error]); }); } else { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestorePlugin.m b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestorePlugin.m index b7fa740fe68c..2e5071acdd5a 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestorePlugin.m +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestorePlugin.m @@ -3,11 +3,8 @@ // found in the LICENSE file. @import FirebaseFirestore; -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; #import #import "FirebaseFirestoreInternal/FIRPersistentCacheIndexManager.h" @@ -220,7 +217,8 @@ - (FIRFirestore *_Nullable)getFIRFirestoreFromAppNameFromPigeon: NSString *appNameDart = pigeonApp.appName; NSString *databaseUrl = pigeonApp.databaseURL; - FIRApp *app = [FLTFirebasePlugin firebaseAppNamed:appNameDart]; + FIRApp *app = + [FIRApp appNamed:[FLTFirebasePluginHelper firebaseAppNameFromDartName:appNameDart]]; if ([FLTFirebaseFirestoreUtils getFirestoreInstanceByName:app.name databaseURL:databaseUrl] != nil) { diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreReader.m b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreReader.m index edfa4cba17ae..70fdc803bf0d 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreReader.m +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreReader.m @@ -4,12 +4,8 @@ @import FirebaseFirestore; @import FirebaseCore; +@import firebase_core; -#if __has_include() -#import -#else -#import -#endif #import "include/cloud_firestore/Private/FLTFirebaseFirestoreReader.h" #import "include/cloud_firestore/Private/FLTFirebaseFirestoreUtils.h" @@ -297,7 +293,8 @@ - (FIRFirestore *)FIRFirestore { NSString *appNameDart = [self readValue]; NSString *databaseUrl = [self readValue]; FIRFirestoreSettings *settings = [self readValue]; - FIRApp *app = [FLTFirebasePlugin firebaseAppNamed:appNameDart]; + FIRApp *app = + [FIRApp appNamed:[FLTFirebasePluginHelper firebaseAppNameFromDartName:appNameDart]]; if ([FLTFirebaseFirestoreUtils getFirestoreInstanceByName:app.name databaseURL:databaseUrl] != nil) { diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreWriter.m b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreWriter.m index f2656d38dbc9..6d3308220c35 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreWriter.m +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTFirebaseFirestoreWriter.m @@ -4,6 +4,7 @@ @import FirebaseFirestore; @import FirebaseCore; +@import firebase_core; #import "include/cloud_firestore/Private/FLTFirebaseFirestoreWriter.h" #import "include/cloud_firestore/Private/FLTFirebaseFirestoreUtils.h" @@ -39,7 +40,8 @@ - (void)writeValue:(id)value { } else if ([value isKindOfClass:[FIRDocumentReference class]]) { FIRDocumentReference *document = value; NSString *documentPath = [document path]; - NSString *appName = [FLTFirebasePlugin firebaseAppNameFromIosName:document.firestore.app.name]; + NSString *appName = + [FLTFirebasePluginHelper firebaseAppNameFromIosName:document.firestore.app.name]; [self writeByte:FirestoreDataTypeDocumentReference]; [self writeValue:appName]; [self writeValue:documentPath]; diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTLoadBundleStreamHandler.m b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTLoadBundleStreamHandler.m index cc8bd9be9ae2..2c40b70deb92 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTLoadBundleStreamHandler.m +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTLoadBundleStreamHandler.m @@ -10,11 +10,7 @@ // @import FirebaseFirestore; -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; #import "include/cloud_firestore/Private/FLTFirebaseFirestoreUtils.h" #import "include/cloud_firestore/Private/FLTLoadBundleStreamHandler.h" @@ -52,10 +48,10 @@ - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments }; dispatch_async(dispatch_get_main_queue(), ^{ - events([FLTFirebasePlugin createFlutterErrorFromCode:code - message:message - optionalDetails:details - andOptionalNSError:error]); + events([FLTFirebasePluginHelper createFlutterErrorWithCode:code + message:message + optionalDetails:details + andOptionalError:error]); }); } }]; diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTQuerySnapshotStreamHandler.m b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTQuerySnapshotStreamHandler.m index bb80a2d6e69e..b3700059e3bf 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTQuerySnapshotStreamHandler.m +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTQuerySnapshotStreamHandler.m @@ -3,11 +3,7 @@ // found in the LICENSE file. @import FirebaseFirestore; -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; #import "include/cloud_firestore/Private/FLTFirebaseFirestoreUtils.h" #import "include/cloud_firestore/Private/FLTQuerySnapshotStreamHandler.h" @@ -58,10 +54,10 @@ - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments @"message" : message, }; dispatch_async(dispatch_get_main_queue(), ^{ - events([FLTFirebasePlugin createFlutterErrorFromCode:code - message:message - optionalDetails:details - andOptionalNSError:error]); + events([FLTFirebasePluginHelper createFlutterErrorWithCode:code + message:message + optionalDetails:details + andOptionalError:error]); }); } else { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTTransactionStreamHandler.m b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTTransactionStreamHandler.m index 29252ca4821c..9284ff4f287d 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTTransactionStreamHandler.m +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/FLTTransactionStreamHandler.m @@ -3,11 +3,8 @@ // found in the LICENSE file. @import FirebaseFirestore; -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; #import "include/cloud_firestore/Private/FLTFirebaseFirestoreUtils.h" #import "include/cloud_firestore/Private/FLTTransactionStreamHandler.h" @@ -55,8 +52,9 @@ - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments strongSelf.started(transaction); dispatch_async(dispatch_get_main_queue(), ^{ - events( - @{@"appName" : [FLTFirebasePlugin firebaseAppNameFromIosName:self.firestore.app.name]}); + events(@{ + @"appName" : [FLTFirebasePluginHelper firebaseAppNameFromIosName:self.firestore.app.name] + }); }); long timedOut = dispatch_semaphore_wait( diff --git a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/include/cloud_firestore/Public/FLTFirebaseFirestorePlugin.h b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/include/cloud_firestore/Public/FLTFirebaseFirestorePlugin.h index 85e38b5ee2a5..1073d7b86169 100644 --- a/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/include/cloud_firestore/Public/FLTFirebaseFirestorePlugin.h +++ b/packages/cloud_firestore/cloud_firestore/ios/cloud_firestore/Sources/cloud_firestore/include/cloud_firestore/Public/FLTFirebaseFirestorePlugin.h @@ -10,14 +10,10 @@ #endif #import -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; #import "FirestoreMessages.g.h" @interface FLTFirebaseFirestorePlugin - : FLTFirebasePlugin + : NSObject + (NSMutableDictionary *)serverTimestampMap; @end diff --git a/packages/cloud_functions/cloud_functions/android/src/main/kotlin/io/flutter/plugins/firebase/functions/FlutterFirebaseFunctionsPlugin.kt b/packages/cloud_functions/cloud_functions/android/src/main/kotlin/io/flutter/plugins/firebase/functions/FlutterFirebaseFunctionsPlugin.kt index 3705e390c0b8..6f20d1e76835 100644 --- a/packages/cloud_functions/cloud_functions/android/src/main/kotlin/io/flutter/plugins/firebase/functions/FlutterFirebaseFunctionsPlugin.kt +++ b/packages/cloud_functions/cloud_functions/android/src/main/kotlin/io/flutter/plugins/firebase/functions/FlutterFirebaseFunctionsPlugin.kt @@ -159,8 +159,8 @@ class FlutterFirebaseFunctionsPlugin return taskCompletionSource.task } - override fun didReinitializeFirebaseCore(): Task { - val taskCompletionSource = TaskCompletionSource() + override fun didReinitializeFirebaseCore(): Task { + val taskCompletionSource = TaskCompletionSource() FlutterFirebasePlugin.cachedThreadPool.execute { taskCompletionSource.setResult(null) } diff --git a/packages/cloud_functions/cloud_functions/ios/cloud_functions/Sources/cloud_functions/FirebaseFunctionsPlugin.swift b/packages/cloud_functions/cloud_functions/ios/cloud_functions/Sources/cloud_functions/FirebaseFunctionsPlugin.swift index 7163bdda6f10..d79164d5c42d 100644 --- a/packages/cloud_functions/cloud_functions/ios/cloud_functions/Sources/cloud_functions/FirebaseFunctionsPlugin.swift +++ b/packages/cloud_functions/cloud_functions/ios/cloud_functions/Sources/cloud_functions/FirebaseFunctionsPlugin.swift @@ -13,13 +13,14 @@ #else import firebase_core_shared #endif +import FirebaseCore import FirebaseFunctions extension FlutterError: Error {} let kFLTFirebaseFunctionsChannelName = "plugins.flutter.io/firebase_functions" -public class FirebaseFunctionsPlugin: NSObject, FLTFirebasePluginProtocol, FlutterPlugin, +public class FirebaseFunctionsPlugin: NSObject, FLTFirebasePlugin, FlutterPlugin, CloudFunctionsHostApi { func call(arguments: [String: Any?], completion: @escaping (Result) -> Void) { httpsFunctionCall(arguments: arguments) { result, error in @@ -48,23 +49,23 @@ public class FirebaseFunctionsPlugin: NSObject, FLTFirebasePluginProtocol, Flutt self.binaryMessenger = binaryMessenger } - public func firebaseLibraryVersion() -> String { + public var firebaseLibraryVersion: String { versionNumber } - public func didReinitializeFirebaseCore(_ completion: @escaping () -> Void) { + public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { completion() } - public func pluginConstants(for firebaseApp: FirebaseApp) -> [AnyHashable: Any] { + public func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] { [:] } - @objc public func firebaseLibraryName() -> String { + public var firebaseLibraryName: String { "flutter-fire-fn" } - @objc public func flutterChannelName() -> String { + public var flutterChannelName: String { kFLTFirebaseFunctionsChannelName } @@ -91,7 +92,7 @@ public class FirebaseFunctionsPlugin: NSObject, FLTFirebasePluginProtocol, Flutt let parameters = arguments["parameters"] let limitedUseAppCheckToken = arguments["limitedUseAppCheckToken"] as? Bool ?? false - let app = FLTFirebasePlugin.firebaseAppNamed(appName)! + let app = FLTFirebasePluginHelper.firebaseApp(named: appName)! let functions = Functions.functions(app: app, region: region ?? "") @@ -138,7 +139,7 @@ public class FirebaseFunctionsPlugin: NSObject, FLTFirebasePluginProtocol, Flutt private func getFunctions(arguments: [String: Any]) -> Functions { let appName = arguments["appName"] as? String ?? "" let region = arguments["region"] as? String - let app = FLTFirebasePlugin.firebaseAppNamed(appName)! + let app = FLTFirebasePluginHelper.firebaseApp(named: appName)! return Functions.functions(app: app, region: region ?? "") } diff --git a/packages/cloud_functions/cloud_functions/macos/cloud_functions.podspec b/packages/cloud_functions/cloud_functions/macos/cloud_functions.podspec index ca265c77aff7..7557b2eda5d7 100644 --- a/packages/cloud_functions/cloud_functions/macos/cloud_functions.podspec +++ b/packages/cloud_functions/cloud_functions/macos/cloud_functions.podspec @@ -42,7 +42,6 @@ Pod::Spec.new do |s| s.authors = 'The Chromium Authors' s.source = { :path => '.' } s.source_files = 'cloud_functions/Sources/**/*.swift' - s.public_header_files = 'cloud_functions/Sources/cloud_functions/include/*.h' s.platform = :osx, '10.15' s.swift_version = '5.0' diff --git a/packages/firebase_analytics/firebase_analytics/android/src/main/kotlin/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.kt b/packages/firebase_analytics/firebase_analytics/android/src/main/kotlin/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.kt index aca07f356d51..ec7ad181ff94 100644 --- a/packages/firebase_analytics/firebase_analytics/android/src/main/kotlin/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.kt +++ b/packages/firebase_analytics/firebase_analytics/android/src/main/kotlin/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.kt @@ -18,7 +18,6 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.plugin.common.BinaryMessenger import io.flutter.plugin.common.MethodChannel import io.flutter.plugins.firebase.core.FlutterFirebasePlugin -import io.flutter.plugins.firebase.core.FlutterFirebasePlugin.cachedThreadPool import io.flutter.plugins.firebase.core.FlutterFirebasePluginRegistry import java.util.Objects @@ -39,10 +38,10 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, this.messenger = messenger } - override fun getPluginConstantsForFirebaseApp(firebaseApp: FirebaseApp?): Task> { - val taskCompletionSource = TaskCompletionSource>() + override fun getPluginConstantsForFirebaseApp(firebaseApp: FirebaseApp): Task> { + val taskCompletionSource = TaskCompletionSource>() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { taskCompletionSource.setResult(HashMap()) } catch (e: Exception) { @@ -53,10 +52,10 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, return taskCompletionSource.task } - override fun didReinitializeFirebaseCore(): Task { - val taskCompletionSource = TaskCompletionSource() + override fun didReinitializeFirebaseCore(): Task { + val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { taskCompletionSource.setResult(null) } catch (e: java.lang.Exception) { @@ -84,7 +83,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleGetSessionId(): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { taskCompletionSource.setResult( Tasks.await( @@ -102,7 +101,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleLogEvent(arguments: Map): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { val eventName = Objects.requireNonNull(arguments[Constants.EVENT_NAME]) as String @@ -125,7 +124,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleSetUserId(userId: String?): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { analytics.setUserId(userId) taskCompletionSource.setResult(null) @@ -140,7 +139,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleSetAnalyticsCollectionEnabled(enabled: Boolean): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { analytics.setAnalyticsCollectionEnabled(enabled) taskCompletionSource.setResult(null) @@ -155,7 +154,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleSetSessionTimeoutDuration(milliseconds: Long): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { analytics.setSessionTimeoutDuration(milliseconds) taskCompletionSource.setResult(null) @@ -170,7 +169,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleSetUserProperty(name: String, value: String?): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { analytics.setUserProperty(name, value) taskCompletionSource.setResult(null) @@ -185,7 +184,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleResetAnalyticsData(): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { analytics.resetAnalyticsData() taskCompletionSource.setResult(null) @@ -200,7 +199,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleSetConsent(arguments: Map): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { val adStorageGranted = arguments[Constants.AD_STORAGE_CONSENT_GRANTED] @@ -255,7 +254,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleSetDefaultEventParameters(parameters: Map?): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { analytics.setDefaultEventParameters( createBundleFromMap( @@ -274,7 +273,7 @@ class FlutterFirebaseAnalyticsPlugin : FlutterFirebasePlugin, private fun handleGetAppInstanceId(): Task { val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + FlutterFirebasePlugin.cachedThreadPool.execute { try { taskCompletionSource.setResult( Tasks.await( diff --git a/packages/firebase_analytics/firebase_analytics/example/android/app/build.gradle b/packages/firebase_analytics/firebase_analytics/example/android/app/build.gradle index c05ed68b6947..c14bfd758a56 100644 --- a/packages/firebase_analytics/firebase_analytics/example/android/app/build.gradle +++ b/packages/firebase_analytics/firebase_analytics/example/android/app/build.gradle @@ -45,7 +45,7 @@ android { applicationId = "io.flutter.plugins.firebase.analytics.example" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdk = 23 + minSdkVersion = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = flutterVersionCode.toInteger() versionName = flutterVersionName diff --git a/packages/firebase_analytics/firebase_analytics/ios/firebase_analytics/Sources/firebase_analytics/FirebaseAnalyticsPlugin.swift b/packages/firebase_analytics/firebase_analytics/ios/firebase_analytics/Sources/firebase_analytics/FirebaseAnalyticsPlugin.swift index fcd6bda21819..ed816e41234f 100644 --- a/packages/firebase_analytics/firebase_analytics/ios/firebase_analytics/Sources/firebase_analytics/FirebaseAnalyticsPlugin.swift +++ b/packages/firebase_analytics/firebase_analytics/ios/firebase_analytics/Sources/firebase_analytics/FirebaseAnalyticsPlugin.swift @@ -14,6 +14,7 @@ import firebase_core_shared #endif import FirebaseAnalytics +import FirebaseCore let kFLTFirebaseAnalyticsName = "name" let kFLTFirebaseAnalyticsValue = "value" @@ -28,7 +29,7 @@ let kFLTFirebaseAnalyticsUserId = "userId" let FLTFirebaseAnalyticsChannelName = "plugins.flutter.io/firebase_analytics" -public class FirebaseAnalyticsPlugin: NSObject, FLTFirebasePluginProtocol, FlutterPlugin, +public class FirebaseAnalyticsPlugin: NSObject, FLTFirebasePlugin, FlutterPlugin, FirebaseAnalyticsHostApi { public static func register(with registrar: any FlutterPluginRegistrar) { let binaryMessenger: FlutterBinaryMessenger @@ -142,23 +143,23 @@ public class FirebaseAnalyticsPlugin: NSObject, FLTFirebasePluginProtocol, Flutt completion(.success(())) } - public func didReinitializeFirebaseCore(_ completion: @escaping () -> Void) { + public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { completion() } - public func pluginConstants(for firebaseApp: FirebaseApp) -> [AnyHashable: Any] { + public func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] { [:] } - public func firebaseLibraryName() -> String { + public var firebaseLibraryName: String { "flutter-fire-analytics" } - public func firebaseLibraryVersion() -> String { + public var firebaseLibraryVersion: String { versionNumber } - public func flutterChannelName() -> String { + public var flutterChannelName: String { FLTFirebaseAnalyticsChannelName } } diff --git a/packages/firebase_analytics/firebase_analytics/macos/firebase_analytics.podspec b/packages/firebase_analytics/firebase_analytics/macos/firebase_analytics.podspec index 98e9951f889c..21cbdcb88b1c 100755 --- a/packages/firebase_analytics/firebase_analytics/macos/firebase_analytics.podspec +++ b/packages/firebase_analytics/firebase_analytics/macos/firebase_analytics.podspec @@ -49,7 +49,6 @@ Pod::Spec.new do |s| s.source = { :path => '.' } s.source_files = 'firebase_analytics/Sources/firebase_analytics/**/*.swift' - s.public_header_files = 'firebase_analytics/Sources/firebase_analytics/include/*.h' s.platform = :osx, '10.13' s.swift_version = '5.0' diff --git a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FLTFirebaseAppCheckPlugin.m b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FLTFirebaseAppCheckPlugin.m index 7c47283e60b9..9c0e4375d994 100644 --- a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FLTFirebaseAppCheckPlugin.m +++ b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/FLTFirebaseAppCheckPlugin.m @@ -6,12 +6,8 @@ #import "FLTTokenRefreshStreamHandler.h" @import FirebaseAppCheck; - -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; #import "FLTAppCheckProviderFactory.h" @@ -70,9 +66,10 @@ - (void)detachFromEngineForRegistrar:(NSObject *)registr } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutterResult { - FLTFirebaseMethodCallErrorBlock errorBlock = ^( - NSString *_Nullable code, NSString *_Nullable message, NSDictionary *_Nullable details, - NSError *_Nullable error) { + void (^errorBlock)(NSString *_Nullable, NSString *_Nullable, NSDictionary *_Nullable, + NSError *_Nullable) = ^(NSString *_Nullable code, NSString *_Nullable message, + NSDictionary *_Nullable details, + NSError *_Nullable error) { NSMutableDictionary *errorDetails = [NSMutableDictionary dictionary]; NSString *errorCode; @@ -125,7 +122,7 @@ - (void)activate:(id)arguments withMethodCallResult:(FLTFirebaseMethodCallResult NSString *providerName = arguments[@"appleProvider"]; NSString *debugToken = arguments[@"appleDebugToken"]; - FIRApp *app = [FLTFirebasePlugin firebaseAppNamed:appNameDart]; + FIRApp *app = [FIRApp appNamed:[FLTFirebasePluginHelper firebaseAppNameFromDartName:appNameDart]]; [self->providerFactory configure:app providerName:providerName debugToken:debugToken]; result.success(nil); } @@ -184,11 +181,11 @@ - (void)setTokenAutoRefreshEnabled:(id)arguments #pragma mark - FLTFirebasePlugin -- (void)didReinitializeFirebaseCore:(void (^)(void))completion { +- (void)didReinitializeFirebaseCoreWithCompletion:(void (^)(void))completion { [self cleanupWithCompletion:completion]; } -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *)firebase_app { +- (NSDictionary *_Nonnull)pluginConstantsFor:(FIRApp *)firebase_app { return @{}; } @@ -208,7 +205,7 @@ - (NSString *_Nonnull)flutterChannelName { - (FIRAppCheck *_Nullable)getFIRAppCheckFromArguments:(NSDictionary *)arguments { NSString *appNameDart = arguments[@"appName"]; - FIRApp *app = [FLTFirebasePlugin firebaseAppNamed:appNameDart]; + FIRApp *app = [FIRApp appNamed:[FLTFirebasePluginHelper firebaseAppNameFromDartName:appNameDart]]; FIRAppCheck *appCheck = [FIRAppCheck appCheckWithApp:app]; return appCheck; diff --git a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/include/FLTFirebaseAppCheckPlugin.h b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/include/FLTFirebaseAppCheckPlugin.h index 9d07d0ebc671..3e5a3adcb812 100644 --- a/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/include/FLTFirebaseAppCheckPlugin.h +++ b/packages/firebase_app_check/firebase_app_check/ios/firebase_app_check/Sources/firebase_app_check/include/FLTFirebaseAppCheckPlugin.h @@ -10,12 +10,8 @@ #endif #import -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; #import "FLTAppCheckProviderFactory.h" -@interface FLTFirebaseAppCheckPlugin : FLTFirebasePlugin +@interface FLTFirebaseAppCheckPlugin : NSObject @end diff --git a/packages/firebase_app_installations/firebase_app_installations/ios/firebase_app_installations/Sources/firebase_app_installations/FirebaseInstallationsPlugin.swift b/packages/firebase_app_installations/firebase_app_installations/ios/firebase_app_installations/Sources/firebase_app_installations/FirebaseInstallationsPlugin.swift index fb9ed2a06894..0e43d5163add 100644 --- a/packages/firebase_app_installations/firebase_app_installations/ios/firebase_app_installations/Sources/firebase_app_installations/FirebaseInstallationsPlugin.swift +++ b/packages/firebase_app_installations/firebase_app_installations/ios/firebase_app_installations/Sources/firebase_app_installations/FirebaseInstallationsPlugin.swift @@ -13,11 +13,12 @@ #else import firebase_core_shared #endif +import FirebaseCore import FirebaseInstallations let kFLTFirebaseInstallationsChannelName = "plugins.flutter.io/firebase_app_installations" -public class FirebaseInstallationsPlugin: NSObject, FLTFirebasePluginProtocol, FlutterPlugin { +public class FirebaseInstallationsPlugin: NSObject, FLTFirebasePlugin, FlutterPlugin { private var eventSink: FlutterEventSink? private var messenger: FlutterBinaryMessenger private var streamHandler = [String: IdChangedStreamHandler?]() @@ -40,34 +41,34 @@ public class FirebaseInstallationsPlugin: NSObject, FLTFirebasePluginProtocol, F binaryMessenger: binaryMessenger ) let instance = FirebaseInstallationsPlugin(messenger: binaryMessenger) - FLTFirebasePluginRegistry.sharedInstance().register(instance) + FLTFirebasePluginRegistry.sharedInstance().registerFirebasePlugin(instance) registrar.addMethodCallDelegate(instance, channel: channel) } - public func firebaseLibraryVersion() -> String { - versionNumber - } - - public func didReinitializeFirebaseCore(_ completion: @escaping () -> Void) { + public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { completion() } - public func pluginConstants(for firebaseApp: FirebaseApp) -> [AnyHashable: Any] { + public func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] { [:] } - @objc public func firebaseLibraryName() -> String { + public var firebaseLibraryName: String { "flutter-fire-installations" } - @objc public func flutterChannelName() -> String { + public var firebaseLibraryVersion: String { + versionNumber + } + + public var flutterChannelName: String { kFLTFirebaseInstallationsChannelName } /// Gets Installations instance for a Firebase App. /// - Returns: a Firebase Installations instance for the passed app from Dart private func getInstallations(appName: String) -> Installations { - let app: FirebaseApp = FLTFirebasePlugin.firebaseAppNamed(appName)! + let app: FirebaseApp = FLTFirebasePluginHelper.firebaseApp(named: appName)! return Installations.installations(app: app) } @@ -188,12 +189,14 @@ public class FirebaseInstallationsPlugin: NSObject, FLTFirebasePluginProtocol, F ) } - result(FLTFirebasePlugin.createFlutterError(fromCode: errorDetails["code"] as! String, - message: errorDetails["message"] as! String, - optionalDetails: errorDetails[ - "additionalData" - ] as? [AnyHashable: Any], - andOptionalNSError: error)) + result(FLTFirebasePluginHelper.createFlutterError(code: errorDetails["code"] as! String, + message: errorDetails[ + "message" + ] as! String, + optionalDetails: errorDetails[ + "additionalData" + ] as? [String: Any], + andOptionalError: error)) } switch call.method { diff --git a/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/FLTFirebaseAuthPlugin.m b/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/FLTFirebaseAuthPlugin.m index c55ea4144e03..9539c92bb8ef 100644 --- a/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/FLTFirebaseAuthPlugin.m +++ b/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/FLTFirebaseAuthPlugin.m @@ -3,13 +3,10 @@ // found in the LICENSE file. @import FirebaseAuth; +@import firebase_core; +@import FirebaseCore; #import #import -#if __has_include() -#import -#else -#import -#endif #import "include/Private/FLTAuthStateChannelStreamHandler.h" #import "include/Private/FLTIdTokenChannelStreamHandler.h" @@ -21,12 +18,6 @@ @import CommonCrypto; #import -#if __has_include() -#import -#else -#import -#endif - NSString *const kFLTFirebaseAuthChannelName = @"plugins.flutter.io/firebase_auth"; // Argument Keys @@ -278,7 +269,7 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction #pragma mark - FLTFirebasePlugin -- (void)didReinitializeFirebaseCore:(void (^_Nonnull)(void))completion { +- (void)didReinitializeFirebaseCoreWithCompletion:(void (^_Nonnull)(void))completion { [self cleanupWithCompletion:completion]; } @@ -294,7 +285,7 @@ - (NSString *_Nonnull)flutterChannelName { return kFLTFirebaseAuthChannelName; } -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *_Nonnull)firebaseApp { +- (NSDictionary *_Nonnull)pluginConstantsFor:(FIRApp *_Nonnull)firebaseApp { FIRAuth *auth = [FIRAuth authWithApp:firebaseApp]; return @{ @"APP_LANGUAGE_CODE" : (id)[auth languageCode] ?: [NSNull null], @@ -659,7 +650,8 @@ + (NSNumber *_Nullable)storeAuthCredentialIfPresent:(NSError *)error { } - (FIRAuth *_Nullable)getFIRAuthFromAppNameFromPigeon:(AuthPigeonFirebaseApp *)pigeonApp { - FIRApp *app = [FLTFirebasePlugin firebaseAppNamed:pigeonApp.appName]; + FIRApp *app = + [FIRApp appNamed:[FLTFirebasePluginHelper firebaseAppNameFromDartName:pigeonApp.appName]]; FIRAuth *auth = [FIRAuth authWithApp:app]; auth.tenantID = pigeonApp.tenantId; diff --git a/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/include/Public/FLTFirebaseAuthPlugin.h b/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/include/Public/FLTFirebaseAuthPlugin.h index ea4a0168a18d..ba81174d62d5 100644 --- a/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/include/Public/FLTFirebaseAuthPlugin.h +++ b/packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/include/Public/FLTFirebaseAuthPlugin.h @@ -12,23 +12,18 @@ #import #import -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; #import "firebase_auth_messages.g.h" -@interface FLTFirebaseAuthPlugin - : FLTFirebasePlugin +@interface FLTFirebaseAuthPlugin : NSObject + (FlutterError *)convertToFlutterError:(NSError *)error; @end diff --git a/packages/firebase_core/firebase_core/android/build.gradle b/packages/firebase_core/firebase_core/android/build.gradle index 33904fddc266..45530450e816 100644 --- a/packages/firebase_core/firebase_core/android/build.gradle +++ b/packages/firebase_core/firebase_core/android/build.gradle @@ -2,13 +2,18 @@ group 'io.flutter.plugins.firebase.core' version '1.0-SNAPSHOT' apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' apply from: file("local-config.gradle") buildscript { + ext.kotlin_version = '1.9.10' repositories { google() mavenCentral() } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } } def getRootProjectExtOrDefaultProperty(name) { @@ -36,6 +41,10 @@ android { targetCompatibility project.ext.javaVersion } + kotlinOptions { + jvmTarget = project.ext.javaVersion + } + buildFeatures { buildConfig true } @@ -49,6 +58,7 @@ android { implementation "com.google.firebase:firebase-common" implementation 'androidx.annotation:annotation:1.7.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } } diff --git a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.java b/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.java deleted file mode 100644 index 53b7e6356457..000000000000 --- a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.java +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -package io.flutter.plugins.firebase.core; - -import static io.flutter.plugins.firebase.core.FlutterFirebasePlugin.cachedThreadPool; - -import android.content.Context; -import android.os.Looper; -import androidx.annotation.NonNull; -import com.google.android.gms.tasks.Task; -import com.google.android.gms.tasks.TaskCompletionSource; -import com.google.android.gms.tasks.Tasks; -import com.google.firebase.FirebaseApp; -import com.google.firebase.FirebaseOptions; -import io.flutter.embedding.engine.plugins.FlutterPlugin; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Flutter plugin implementation controlling the entrypoint for the Firebase SDK. - * - *

Instantiate this in an add to app scenario to gracefully handle activity and context changes. - */ -public class FlutterFirebaseCorePlugin - implements FlutterPlugin, - GeneratedAndroidFirebaseCore.FirebaseCoreHostApi, - GeneratedAndroidFirebaseCore.FirebaseAppHostApi { - private Context applicationContext; - private boolean coreInitialized = false; - - public static Map customAuthDomain = new HashMap<>(); - - @Override - public void onAttachedToEngine(FlutterPluginBinding binding) { - GeneratedAndroidFirebaseCore.FirebaseCoreHostApi.setUp(binding.getBinaryMessenger(), this); - GeneratedAndroidFirebaseCore.FirebaseAppHostApi.setUp(binding.getBinaryMessenger(), this); - applicationContext = binding.getApplicationContext(); - } - - @Override - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - applicationContext = null; - GeneratedAndroidFirebaseCore.FirebaseCoreHostApi.setUp(binding.getBinaryMessenger(), null); - GeneratedAndroidFirebaseCore.FirebaseAppHostApi.setUp(binding.getBinaryMessenger(), null); - } - - private GeneratedAndroidFirebaseCore.CoreFirebaseOptions firebaseOptionsToMap( - FirebaseOptions options) { - GeneratedAndroidFirebaseCore.CoreFirebaseOptions.Builder firebaseOptions = - new GeneratedAndroidFirebaseCore.CoreFirebaseOptions.Builder(); - - firebaseOptions.setApiKey(options.getApiKey()); - firebaseOptions.setAppId(options.getApplicationId()); - if (options.getGcmSenderId() != null) { - firebaseOptions.setMessagingSenderId(options.getGcmSenderId()); - } - if (options.getProjectId() != null) { - firebaseOptions.setProjectId(options.getProjectId()); - } - firebaseOptions.setDatabaseURL(options.getDatabaseUrl()); - firebaseOptions.setStorageBucket(options.getStorageBucket()); - firebaseOptions.setTrackingId(options.getGaTrackingId()); - - return firebaseOptions.build(); - } - - private Task firebaseAppToMap( - FirebaseApp firebaseApp) { - TaskCompletionSource taskCompletionSource = - new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - GeneratedAndroidFirebaseCore.CoreInitializeResponse.Builder initializeResponse = - new GeneratedAndroidFirebaseCore.CoreInitializeResponse.Builder(); - - initializeResponse.setName(firebaseApp.getName()); - initializeResponse.setOptions(firebaseOptionsToMap(firebaseApp.getOptions())); - - initializeResponse.setIsAutomaticDataCollectionEnabled( - firebaseApp.isDataCollectionDefaultEnabled()); - initializeResponse.setPluginConstants( - Tasks.await( - FlutterFirebasePluginRegistry.getPluginConstantsForFirebaseApp(firebaseApp))); - - taskCompletionSource.setResult(initializeResponse.build()); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - return taskCompletionSource.getTask(); - } - - private void listenToResponse( - TaskCompletionSource taskCompletionSource, GeneratedAndroidFirebaseCore.Result result) { - taskCompletionSource - .getTask() - .addOnCompleteListener( - task -> { - if (task.isSuccessful()) { - result.success(task.getResult()); - } else { - Exception exception = task.getException(); - result.error(exception); - } - }); - } - - private void listenToVoidResponse( - TaskCompletionSource taskCompletionSource, - GeneratedAndroidFirebaseCore.VoidResult result) { - taskCompletionSource - .getTask() - .addOnCompleteListener( - task -> { - if (task.isSuccessful()) { - result.success(); - } else { - Exception exception = task.getException(); - result.error(exception); - } - }); - } - - @Override - public void initializeApp( - @NonNull String appName, - @NonNull GeneratedAndroidFirebaseCore.CoreFirebaseOptions initializeAppRequest, - GeneratedAndroidFirebaseCore.Result - result) { - TaskCompletionSource taskCompletionSource = - new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - - FirebaseOptions options = - new FirebaseOptions.Builder() - .setApiKey(initializeAppRequest.getApiKey()) - .setApplicationId(initializeAppRequest.getAppId()) - .setDatabaseUrl(initializeAppRequest.getDatabaseURL()) - .setGcmSenderId(initializeAppRequest.getMessagingSenderId()) - .setProjectId(initializeAppRequest.getProjectId()) - .setStorageBucket(initializeAppRequest.getStorageBucket()) - .setGaTrackingId(initializeAppRequest.getTrackingId()) - .build(); - // TODO(Salakar) hacky workaround a bug with FirebaseInAppMessaging causing the error: - // Can't create handler inside thread Thread[pool-3-thread-1,5,main] that has not called Looper.prepare() - // at com.google.firebase.inappmessaging.internal.ForegroundNotifier.(ForegroundNotifier.java:61) - try { - Looper.prepare(); - } catch (Exception e) { - // do nothing - } - - if (initializeAppRequest.getAuthDomain() != null) { - customAuthDomain.put(appName, initializeAppRequest.getAuthDomain()); - } - - FirebaseApp firebaseApp = - FirebaseApp.initializeApp(applicationContext, options, appName); - taskCompletionSource.setResult(Tasks.await(firebaseAppToMap(firebaseApp))); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - listenToResponse(taskCompletionSource, result); - } - - @Override - public void initializeCore( - GeneratedAndroidFirebaseCore.Result> - result) { - TaskCompletionSource> - taskCompletionSource = new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - if (!coreInitialized) { - coreInitialized = true; - } else { - Tasks.await(FlutterFirebasePluginRegistry.didReinitializeFirebaseCore()); - } - - List firebaseApps = FirebaseApp.getApps(applicationContext); - List firebaseAppsList = - new ArrayList<>(firebaseApps.size()); - - for (FirebaseApp firebaseApp : firebaseApps) { - firebaseAppsList.add(Tasks.await(firebaseAppToMap(firebaseApp))); - } - - taskCompletionSource.setResult(firebaseAppsList); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - listenToResponse(taskCompletionSource, result); - } - - @Override - public void optionsFromResource( - GeneratedAndroidFirebaseCore.Result - result) { - TaskCompletionSource taskCompletionSource = - new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - final FirebaseOptions options = FirebaseOptions.fromResource(applicationContext); - if (options == null) { - taskCompletionSource.setException( - new Exception( - "Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.")); - return; - } - taskCompletionSource.setResult(firebaseOptionsToMap(options)); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - listenToResponse(taskCompletionSource, result); - } - - @Override - public void setAutomaticDataCollectionEnabled( - @NonNull String appName, - @NonNull Boolean enabled, - GeneratedAndroidFirebaseCore.VoidResult result) { - TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); - firebaseApp.setDataCollectionDefaultEnabled(enabled); - - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - listenToVoidResponse(taskCompletionSource, result); - } - - @Override - public void setAutomaticResourceManagementEnabled( - @NonNull String appName, - @NonNull Boolean enabled, - GeneratedAndroidFirebaseCore.VoidResult result) { - TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); - firebaseApp.setAutomaticResourceManagementEnabled(enabled); - - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - listenToVoidResponse(taskCompletionSource, result); - } - - @Override - public void delete(@NonNull String appName, GeneratedAndroidFirebaseCore.VoidResult result) { - TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); - try { - firebaseApp.delete(); - } catch (IllegalStateException appNotFoundException) { - // Ignore app not found exceptions. - } - - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - listenToVoidResponse(taskCompletionSource, result); - } -} diff --git a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCoreRegistrar.java b/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCoreRegistrar.java deleted file mode 100644 index e12a3795e75f..000000000000 --- a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCoreRegistrar.java +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.firebase.core; - -import androidx.annotation.Keep; -import com.google.firebase.components.Component; -import com.google.firebase.components.ComponentRegistrar; -import com.google.firebase.platforminfo.LibraryVersionComponent; -import java.util.Collections; -import java.util.List; - -@Keep -public class FlutterFirebaseCoreRegistrar implements ComponentRegistrar { - @Override - public List> getComponents() { - return Collections.singletonList( - LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION)); - } -} diff --git a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebasePlugin.java b/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebasePlugin.java deleted file mode 100644 index ec31f63e6d62..000000000000 --- a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebasePlugin.java +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -package io.flutter.plugins.firebase.core; - -import androidx.annotation.Keep; -import com.google.android.gms.tasks.Task; -import com.google.firebase.FirebaseApp; -import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -@Keep -public interface FlutterFirebasePlugin { - // A shared ExecutorService used by all FlutterFire Plugins for their GMS Tasks. - ExecutorService cachedThreadPool = Executors.newCachedThreadPool(); - - /** - * FlutterFire plugins implementing FlutterFirebasePlugin must provide this method to provide it's - * constants that are initialized during FirebaseCore.initializeApp in Dart. - * - * @param firebaseApp The Firebase App that the plugin should return constants for. - * @return A task returning the discovered constants for the plugin for the provided Firebase App. - */ - Task> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp); - - /** - * FlutterFire plugins implementing FlutterFirebasePlugin should provide this method to be - * notified when FirebaseCore#initializeCore was called again (first time is ignored). - * - *

This can be used by plugins to know when they might need to cleanup previous resources - * between Hot Restarts as `initializeCore` can only be called once in Dart. - */ - Task didReinitializeFirebaseCore(); -} diff --git a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebasePluginRegistry.java b/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebasePluginRegistry.java deleted file mode 100644 index 84fdbc7ce279..000000000000 --- a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebasePluginRegistry.java +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -package io.flutter.plugins.firebase.core; - -import static io.flutter.plugins.firebase.core.FlutterFirebasePlugin.cachedThreadPool; - -import androidx.annotation.Keep; -import com.google.android.gms.tasks.Task; -import com.google.android.gms.tasks.TaskCompletionSource; -import com.google.android.gms.tasks.Tasks; -import com.google.firebase.FirebaseApp; -import java.util.HashMap; -import java.util.Map; -import java.util.WeakHashMap; - -@Keep -public class FlutterFirebasePluginRegistry { - - private static final Map registeredPlugins = new WeakHashMap<>(); - - /** - * Register a Flutter Firebase plugin with the Firebase plugin registry. - * - * @param channelName The MethodChannel name for the plugin to be registered, for example: - * `plugins.flutter.io/firebase_core` - * @param flutterFirebasePlugin A FlutterPlugin that implements FlutterFirebasePlugin. - */ - public static void registerPlugin( - String channelName, FlutterFirebasePlugin flutterFirebasePlugin) { - registeredPlugins.put(channelName, flutterFirebasePlugin); - } - - /** - * Each FlutterFire plugin implementing FlutterFirebasePlugin provides this method allowing it's - * constants to be initialized during FirebaseCore.initializeApp in Dart. Here we call this method - * on each of the registered plugins and gather their constants for use in Dart. - * - * @param firebaseApp The Firebase App that the plugin should return constants for. - * @return A task returning the discovered constants for each plugin (using channelName as the Map - * key) for the provided Firebase App. - */ - static Task> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) { - TaskCompletionSource> taskCompletionSource = new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - Map pluginConstants = new HashMap<>(registeredPlugins.size()); - - for (Map.Entry entry : registeredPlugins.entrySet()) { - String channelName = entry.getKey(); - FlutterFirebasePlugin plugin = entry.getValue(); - pluginConstants.put( - channelName, Tasks.await(plugin.getPluginConstantsForFirebaseApp(firebaseApp))); - } - - taskCompletionSource.setResult(pluginConstants); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - return taskCompletionSource.getTask(); - } - - /** - * Each FlutterFire plugin implementing this method are notified that FirebaseCore#initializeCore - * was called again. - * - *

This is used by plugins to know if they need to cleanup previous resources between Hot - * Restarts as `initializeCore` can only be called once in Dart. - */ - static Task didReinitializeFirebaseCore() { - TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); - - cachedThreadPool.execute( - () -> { - try { - for (Map.Entry entry : registeredPlugins.entrySet()) { - FlutterFirebasePlugin plugin = entry.getValue(); - Tasks.await(plugin.didReinitializeFirebaseCore()); - } - - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); - - return taskCompletionSource.getTask(); - } -} diff --git a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.java b/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.java deleted file mode 100644 index af1dec848522..000000000000 --- a/packages/firebase_core/firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.java +++ /dev/null @@ -1,906 +0,0 @@ -// Copyright 2023, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -// Autogenerated from Pigeon (v25.3.2), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -package io.flutter.plugins.firebase.core; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.CLASS; - -import android.util.Log; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import io.flutter.plugin.common.BasicMessageChannel; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.common.MessageCodec; -import io.flutter.plugin.common.StandardMessageCodec; -import java.io.ByteArrayOutputStream; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** Generated class from Pigeon. */ -@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) -public class GeneratedAndroidFirebaseCore { - - /** Error class for passing custom error details to Flutter via a thrown PlatformException. */ - public static class FlutterError extends RuntimeException { - - /** The error code. */ - public final String code; - - /** The error details. Must be a datatype supported by the api codec. */ - public final Object details; - - public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) { - super(message); - this.code = code; - this.details = details; - } - } - - @NonNull - protected static ArrayList wrapError(@NonNull Throwable exception) { - ArrayList errorList = new ArrayList<>(3); - if (exception instanceof FlutterError) { - FlutterError error = (FlutterError) exception; - errorList.add(error.code); - errorList.add(error.getMessage()); - errorList.add(error.details); - } else { - errorList.add(exception.toString()); - errorList.add(exception.getClass().getSimpleName()); - errorList.add( - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); - } - return errorList; - } - - @Target(METHOD) - @Retention(CLASS) - @interface CanIgnoreReturnValue {} - - /** Generated class from Pigeon that represents data sent in messages. */ - public static final class CoreFirebaseOptions { - private @NonNull String apiKey; - - public @NonNull String getApiKey() { - return apiKey; - } - - public void setApiKey(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"apiKey\" is null."); - } - this.apiKey = setterArg; - } - - private @NonNull String appId; - - public @NonNull String getAppId() { - return appId; - } - - public void setAppId(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"appId\" is null."); - } - this.appId = setterArg; - } - - private @NonNull String messagingSenderId; - - public @NonNull String getMessagingSenderId() { - return messagingSenderId; - } - - public void setMessagingSenderId(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"messagingSenderId\" is null."); - } - this.messagingSenderId = setterArg; - } - - private @NonNull String projectId; - - public @NonNull String getProjectId() { - return projectId; - } - - public void setProjectId(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"projectId\" is null."); - } - this.projectId = setterArg; - } - - private @Nullable String authDomain; - - public @Nullable String getAuthDomain() { - return authDomain; - } - - public void setAuthDomain(@Nullable String setterArg) { - this.authDomain = setterArg; - } - - private @Nullable String databaseURL; - - public @Nullable String getDatabaseURL() { - return databaseURL; - } - - public void setDatabaseURL(@Nullable String setterArg) { - this.databaseURL = setterArg; - } - - private @Nullable String storageBucket; - - public @Nullable String getStorageBucket() { - return storageBucket; - } - - public void setStorageBucket(@Nullable String setterArg) { - this.storageBucket = setterArg; - } - - private @Nullable String measurementId; - - public @Nullable String getMeasurementId() { - return measurementId; - } - - public void setMeasurementId(@Nullable String setterArg) { - this.measurementId = setterArg; - } - - private @Nullable String trackingId; - - public @Nullable String getTrackingId() { - return trackingId; - } - - public void setTrackingId(@Nullable String setterArg) { - this.trackingId = setterArg; - } - - private @Nullable String deepLinkURLScheme; - - public @Nullable String getDeepLinkURLScheme() { - return deepLinkURLScheme; - } - - public void setDeepLinkURLScheme(@Nullable String setterArg) { - this.deepLinkURLScheme = setterArg; - } - - private @Nullable String androidClientId; - - public @Nullable String getAndroidClientId() { - return androidClientId; - } - - public void setAndroidClientId(@Nullable String setterArg) { - this.androidClientId = setterArg; - } - - private @Nullable String iosClientId; - - public @Nullable String getIosClientId() { - return iosClientId; - } - - public void setIosClientId(@Nullable String setterArg) { - this.iosClientId = setterArg; - } - - private @Nullable String iosBundleId; - - public @Nullable String getIosBundleId() { - return iosBundleId; - } - - public void setIosBundleId(@Nullable String setterArg) { - this.iosBundleId = setterArg; - } - - private @Nullable String appGroupId; - - public @Nullable String getAppGroupId() { - return appGroupId; - } - - public void setAppGroupId(@Nullable String setterArg) { - this.appGroupId = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - CoreFirebaseOptions() {} - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - CoreFirebaseOptions that = (CoreFirebaseOptions) o; - return apiKey.equals(that.apiKey) - && appId.equals(that.appId) - && messagingSenderId.equals(that.messagingSenderId) - && projectId.equals(that.projectId) - && Objects.equals(authDomain, that.authDomain) - && Objects.equals(databaseURL, that.databaseURL) - && Objects.equals(storageBucket, that.storageBucket) - && Objects.equals(measurementId, that.measurementId) - && Objects.equals(trackingId, that.trackingId) - && Objects.equals(deepLinkURLScheme, that.deepLinkURLScheme) - && Objects.equals(androidClientId, that.androidClientId) - && Objects.equals(iosClientId, that.iosClientId) - && Objects.equals(iosBundleId, that.iosBundleId) - && Objects.equals(appGroupId, that.appGroupId); - } - - @Override - public int hashCode() { - return Objects.hash( - apiKey, - appId, - messagingSenderId, - projectId, - authDomain, - databaseURL, - storageBucket, - measurementId, - trackingId, - deepLinkURLScheme, - androidClientId, - iosClientId, - iosBundleId, - appGroupId); - } - - public static final class Builder { - - private @Nullable String apiKey; - - @CanIgnoreReturnValue - public @NonNull Builder setApiKey(@NonNull String setterArg) { - this.apiKey = setterArg; - return this; - } - - private @Nullable String appId; - - @CanIgnoreReturnValue - public @NonNull Builder setAppId(@NonNull String setterArg) { - this.appId = setterArg; - return this; - } - - private @Nullable String messagingSenderId; - - @CanIgnoreReturnValue - public @NonNull Builder setMessagingSenderId(@NonNull String setterArg) { - this.messagingSenderId = setterArg; - return this; - } - - private @Nullable String projectId; - - @CanIgnoreReturnValue - public @NonNull Builder setProjectId(@NonNull String setterArg) { - this.projectId = setterArg; - return this; - } - - private @Nullable String authDomain; - - @CanIgnoreReturnValue - public @NonNull Builder setAuthDomain(@Nullable String setterArg) { - this.authDomain = setterArg; - return this; - } - - private @Nullable String databaseURL; - - @CanIgnoreReturnValue - public @NonNull Builder setDatabaseURL(@Nullable String setterArg) { - this.databaseURL = setterArg; - return this; - } - - private @Nullable String storageBucket; - - @CanIgnoreReturnValue - public @NonNull Builder setStorageBucket(@Nullable String setterArg) { - this.storageBucket = setterArg; - return this; - } - - private @Nullable String measurementId; - - @CanIgnoreReturnValue - public @NonNull Builder setMeasurementId(@Nullable String setterArg) { - this.measurementId = setterArg; - return this; - } - - private @Nullable String trackingId; - - @CanIgnoreReturnValue - public @NonNull Builder setTrackingId(@Nullable String setterArg) { - this.trackingId = setterArg; - return this; - } - - private @Nullable String deepLinkURLScheme; - - @CanIgnoreReturnValue - public @NonNull Builder setDeepLinkURLScheme(@Nullable String setterArg) { - this.deepLinkURLScheme = setterArg; - return this; - } - - private @Nullable String androidClientId; - - @CanIgnoreReturnValue - public @NonNull Builder setAndroidClientId(@Nullable String setterArg) { - this.androidClientId = setterArg; - return this; - } - - private @Nullable String iosClientId; - - @CanIgnoreReturnValue - public @NonNull Builder setIosClientId(@Nullable String setterArg) { - this.iosClientId = setterArg; - return this; - } - - private @Nullable String iosBundleId; - - @CanIgnoreReturnValue - public @NonNull Builder setIosBundleId(@Nullable String setterArg) { - this.iosBundleId = setterArg; - return this; - } - - private @Nullable String appGroupId; - - @CanIgnoreReturnValue - public @NonNull Builder setAppGroupId(@Nullable String setterArg) { - this.appGroupId = setterArg; - return this; - } - - public @NonNull CoreFirebaseOptions build() { - CoreFirebaseOptions pigeonReturn = new CoreFirebaseOptions(); - pigeonReturn.setApiKey(apiKey); - pigeonReturn.setAppId(appId); - pigeonReturn.setMessagingSenderId(messagingSenderId); - pigeonReturn.setProjectId(projectId); - pigeonReturn.setAuthDomain(authDomain); - pigeonReturn.setDatabaseURL(databaseURL); - pigeonReturn.setStorageBucket(storageBucket); - pigeonReturn.setMeasurementId(measurementId); - pigeonReturn.setTrackingId(trackingId); - pigeonReturn.setDeepLinkURLScheme(deepLinkURLScheme); - pigeonReturn.setAndroidClientId(androidClientId); - pigeonReturn.setIosClientId(iosClientId); - pigeonReturn.setIosBundleId(iosBundleId); - pigeonReturn.setAppGroupId(appGroupId); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList<>(14); - toListResult.add(apiKey); - toListResult.add(appId); - toListResult.add(messagingSenderId); - toListResult.add(projectId); - toListResult.add(authDomain); - toListResult.add(databaseURL); - toListResult.add(storageBucket); - toListResult.add(measurementId); - toListResult.add(trackingId); - toListResult.add(deepLinkURLScheme); - toListResult.add(androidClientId); - toListResult.add(iosClientId); - toListResult.add(iosBundleId); - toListResult.add(appGroupId); - return toListResult; - } - - static @NonNull CoreFirebaseOptions fromList(@NonNull ArrayList pigeonVar_list) { - CoreFirebaseOptions pigeonResult = new CoreFirebaseOptions(); - Object apiKey = pigeonVar_list.get(0); - pigeonResult.setApiKey((String) apiKey); - Object appId = pigeonVar_list.get(1); - pigeonResult.setAppId((String) appId); - Object messagingSenderId = pigeonVar_list.get(2); - pigeonResult.setMessagingSenderId((String) messagingSenderId); - Object projectId = pigeonVar_list.get(3); - pigeonResult.setProjectId((String) projectId); - Object authDomain = pigeonVar_list.get(4); - pigeonResult.setAuthDomain((String) authDomain); - Object databaseURL = pigeonVar_list.get(5); - pigeonResult.setDatabaseURL((String) databaseURL); - Object storageBucket = pigeonVar_list.get(6); - pigeonResult.setStorageBucket((String) storageBucket); - Object measurementId = pigeonVar_list.get(7); - pigeonResult.setMeasurementId((String) measurementId); - Object trackingId = pigeonVar_list.get(8); - pigeonResult.setTrackingId((String) trackingId); - Object deepLinkURLScheme = pigeonVar_list.get(9); - pigeonResult.setDeepLinkURLScheme((String) deepLinkURLScheme); - Object androidClientId = pigeonVar_list.get(10); - pigeonResult.setAndroidClientId((String) androidClientId); - Object iosClientId = pigeonVar_list.get(11); - pigeonResult.setIosClientId((String) iosClientId); - Object iosBundleId = pigeonVar_list.get(12); - pigeonResult.setIosBundleId((String) iosBundleId); - Object appGroupId = pigeonVar_list.get(13); - pigeonResult.setAppGroupId((String) appGroupId); - return pigeonResult; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static final class CoreInitializeResponse { - private @NonNull String name; - - public @NonNull String getName() { - return name; - } - - public void setName(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"name\" is null."); - } - this.name = setterArg; - } - - private @NonNull CoreFirebaseOptions options; - - public @NonNull CoreFirebaseOptions getOptions() { - return options; - } - - public void setOptions(@NonNull CoreFirebaseOptions setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"options\" is null."); - } - this.options = setterArg; - } - - private @Nullable Boolean isAutomaticDataCollectionEnabled; - - public @Nullable Boolean getIsAutomaticDataCollectionEnabled() { - return isAutomaticDataCollectionEnabled; - } - - public void setIsAutomaticDataCollectionEnabled(@Nullable Boolean setterArg) { - this.isAutomaticDataCollectionEnabled = setterArg; - } - - private @NonNull Map pluginConstants; - - public @NonNull Map getPluginConstants() { - return pluginConstants; - } - - public void setPluginConstants(@NonNull Map setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"pluginConstants\" is null."); - } - this.pluginConstants = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - CoreInitializeResponse() {} - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - CoreInitializeResponse that = (CoreInitializeResponse) o; - return name.equals(that.name) - && options.equals(that.options) - && Objects.equals(isAutomaticDataCollectionEnabled, that.isAutomaticDataCollectionEnabled) - && pluginConstants.equals(that.pluginConstants); - } - - @Override - public int hashCode() { - return Objects.hash(name, options, isAutomaticDataCollectionEnabled, pluginConstants); - } - - public static final class Builder { - - private @Nullable String name; - - @CanIgnoreReturnValue - public @NonNull Builder setName(@NonNull String setterArg) { - this.name = setterArg; - return this; - } - - private @Nullable CoreFirebaseOptions options; - - @CanIgnoreReturnValue - public @NonNull Builder setOptions(@NonNull CoreFirebaseOptions setterArg) { - this.options = setterArg; - return this; - } - - private @Nullable Boolean isAutomaticDataCollectionEnabled; - - @CanIgnoreReturnValue - public @NonNull Builder setIsAutomaticDataCollectionEnabled(@Nullable Boolean setterArg) { - this.isAutomaticDataCollectionEnabled = setterArg; - return this; - } - - private @Nullable Map pluginConstants; - - @CanIgnoreReturnValue - public @NonNull Builder setPluginConstants(@NonNull Map setterArg) { - this.pluginConstants = setterArg; - return this; - } - - public @NonNull CoreInitializeResponse build() { - CoreInitializeResponse pigeonReturn = new CoreInitializeResponse(); - pigeonReturn.setName(name); - pigeonReturn.setOptions(options); - pigeonReturn.setIsAutomaticDataCollectionEnabled(isAutomaticDataCollectionEnabled); - pigeonReturn.setPluginConstants(pluginConstants); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList<>(4); - toListResult.add(name); - toListResult.add(options); - toListResult.add(isAutomaticDataCollectionEnabled); - toListResult.add(pluginConstants); - return toListResult; - } - - static @NonNull CoreInitializeResponse fromList(@NonNull ArrayList pigeonVar_list) { - CoreInitializeResponse pigeonResult = new CoreInitializeResponse(); - Object name = pigeonVar_list.get(0); - pigeonResult.setName((String) name); - Object options = pigeonVar_list.get(1); - pigeonResult.setOptions((CoreFirebaseOptions) options); - Object isAutomaticDataCollectionEnabled = pigeonVar_list.get(2); - pigeonResult.setIsAutomaticDataCollectionEnabled((Boolean) isAutomaticDataCollectionEnabled); - Object pluginConstants = pigeonVar_list.get(3); - pigeonResult.setPluginConstants((Map) pluginConstants); - return pigeonResult; - } - } - - private static class PigeonCodec extends StandardMessageCodec { - public static final PigeonCodec INSTANCE = new PigeonCodec(); - - private PigeonCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 129: - return CoreFirebaseOptions.fromList((ArrayList) readValue(buffer)); - case (byte) 130: - return CoreInitializeResponse.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof CoreFirebaseOptions) { - stream.write(129); - writeValue(stream, ((CoreFirebaseOptions) value).toList()); - } else if (value instanceof CoreInitializeResponse) { - stream.write(130); - writeValue(stream, ((CoreInitializeResponse) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - - /** Asynchronous error handling return type for non-nullable API method returns. */ - public interface Result { - /** Success case callback method for handling returns. */ - void success(@NonNull T result); - - /** Failure case callback method for handling errors. */ - void error(@NonNull Throwable error); - } - /** Asynchronous error handling return type for nullable API method returns. */ - public interface NullableResult { - /** Success case callback method for handling returns. */ - void success(@Nullable T result); - - /** Failure case callback method for handling errors. */ - void error(@NonNull Throwable error); - } - /** Asynchronous error handling return type for void API method returns. */ - public interface VoidResult { - /** Success case callback method for handling returns. */ - void success(); - - /** Failure case callback method for handling errors. */ - void error(@NonNull Throwable error); - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface FirebaseCoreHostApi { - - void initializeApp( - @NonNull String appName, - @NonNull CoreFirebaseOptions initializeAppRequest, - @NonNull Result result); - - void initializeCore(@NonNull Result> result); - - void optionsFromResource(@NonNull Result result); - - /** The codec used by FirebaseCoreHostApi. */ - static @NonNull MessageCodec getCodec() { - return PigeonCodec.INSTANCE; - } - /** - * Sets up an instance of `FirebaseCoreHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable FirebaseCoreHostApi api) { - setUp(binaryMessenger, "", api); - } - - static void setUp( - @NonNull BinaryMessenger binaryMessenger, - @NonNull String messageChannelSuffix, - @Nullable FirebaseCoreHostApi api) { - messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix; - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeApp" - + messageChannelSuffix, - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); - ArrayList args = (ArrayList) message; - String appNameArg = (String) args.get(0); - CoreFirebaseOptions initializeAppRequestArg = (CoreFirebaseOptions) args.get(1); - Result resultCallback = - new Result() { - public void success(CoreInitializeResponse result) { - wrapped.add(0, result); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.initializeApp(appNameArg, initializeAppRequestArg, resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore" - + messageChannelSuffix, - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); - Result> resultCallback = - new Result>() { - public void success(List result) { - wrapped.add(0, result); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.initializeCore(resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.optionsFromResource" - + messageChannelSuffix, - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); - Result resultCallback = - new Result() { - public void success(CoreFirebaseOptions result) { - wrapped.add(0, result); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.optionsFromResource(resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface FirebaseAppHostApi { - - void setAutomaticDataCollectionEnabled( - @NonNull String appName, @NonNull Boolean enabled, @NonNull VoidResult result); - - void setAutomaticResourceManagementEnabled( - @NonNull String appName, @NonNull Boolean enabled, @NonNull VoidResult result); - - void delete(@NonNull String appName, @NonNull VoidResult result); - - /** The codec used by FirebaseAppHostApi. */ - static @NonNull MessageCodec getCodec() { - return PigeonCodec.INSTANCE; - } - /** - * Sets up an instance of `FirebaseAppHostApi` to handle messages through the `binaryMessenger`. - */ - static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable FirebaseAppHostApi api) { - setUp(binaryMessenger, "", api); - } - - static void setUp( - @NonNull BinaryMessenger binaryMessenger, - @NonNull String messageChannelSuffix, - @Nullable FirebaseAppHostApi api) { - messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix; - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.setAutomaticDataCollectionEnabled" - + messageChannelSuffix, - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); - ArrayList args = (ArrayList) message; - String appNameArg = (String) args.get(0); - Boolean enabledArg = (Boolean) args.get(1); - VoidResult resultCallback = - new VoidResult() { - public void success() { - wrapped.add(0, null); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.setAutomaticDataCollectionEnabled(appNameArg, enabledArg, resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.setAutomaticResourceManagementEnabled" - + messageChannelSuffix, - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); - ArrayList args = (ArrayList) message; - String appNameArg = (String) args.get(0); - Boolean enabledArg = (Boolean) args.get(1); - VoidResult resultCallback = - new VoidResult() { - public void success() { - wrapped.add(0, null); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.setAutomaticResourceManagementEnabled(appNameArg, enabledArg, resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.delete" - + messageChannelSuffix, - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); - ArrayList args = (ArrayList) message; - String appNameArg = (String) args.get(0); - VoidResult resultCallback = - new VoidResult() { - public void success() { - wrapped.add(0, null); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.delete(appNameArg, resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } -} diff --git a/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.kt b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.kt new file mode 100644 index 000000000000..4cc3910d8236 --- /dev/null +++ b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.kt @@ -0,0 +1,198 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +package io.flutter.plugins.firebase.core + +import android.content.Context +import android.os.Looper +import com.google.android.gms.tasks.Tasks +import com.google.firebase.FirebaseApp +import com.google.firebase.FirebaseOptions +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.plugins.firebase.core.FlutterFirebasePlugin.Companion.cachedThreadPool + +/** + * Flutter plugin implementation controlling the entrypoint for the Firebase SDK. + * + * Instantiate this in an add to app scenario to gracefully handle activity and context changes. + */ +class FlutterFirebaseCorePlugin : FlutterPlugin, + FirebaseCoreHostApi, + FirebaseAppHostApi { + + private var applicationContext: Context? = null + private var coreInitialized = false + + override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { + FirebaseCoreHostApi.setUp(binding.binaryMessenger, this) + FirebaseAppHostApi.setUp(binding.binaryMessenger, this) + applicationContext = binding.applicationContext + } + + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { + applicationContext = null + FirebaseCoreHostApi.setUp(binding.binaryMessenger, null) + FirebaseAppHostApi.setUp(binding.binaryMessenger, null) + } + + private fun firebaseOptionsToMap(options: FirebaseOptions): CoreFirebaseOptions { + return CoreFirebaseOptions( + apiKey = options.apiKey, + appId = options.applicationId, + messagingSenderId = options.gcmSenderId ?: "", + projectId = options.projectId ?: "", + authDomain = null, + databaseURL = options.databaseUrl, + storageBucket = options.storageBucket, + measurementId = null, + trackingId = options.gaTrackingId, + deepLinkURLScheme = null, + androidClientId = null, + iosClientId = null, + iosBundleId = null, + appGroupId = null + ) + } + + private fun firebaseAppToMap(firebaseApp: FirebaseApp): CoreInitializeResponse { + val pluginConstants: Map = try { + val constants = Tasks.await(FlutterFirebasePluginRegistry.getPluginConstantsForFirebaseApp(firebaseApp)) + constants.mapKeys { it.key as String? } + } catch (e: Exception) { + emptyMap() + } + + return CoreInitializeResponse( + name = firebaseApp.name, + options = firebaseOptionsToMap(firebaseApp.options), + isAutomaticDataCollectionEnabled = firebaseApp.isDataCollectionDefaultEnabled, + pluginConstants = pluginConstants + ) + } + + override fun initializeApp( + appName: String, + initializeAppRequest: CoreFirebaseOptions, + callback: (Result) -> Unit + ) { + cachedThreadPool.execute { + try { + val options = FirebaseOptions.Builder() + .setApiKey(initializeAppRequest.apiKey) + .setApplicationId(initializeAppRequest.appId) + .setDatabaseUrl(initializeAppRequest.databaseURL) + .setGcmSenderId(initializeAppRequest.messagingSenderId) + .setProjectId(initializeAppRequest.projectId) + .setStorageBucket(initializeAppRequest.storageBucket) + .setGaTrackingId(initializeAppRequest.trackingId) + .build() + + // TODO(Salakar) hacky workaround a bug with FirebaseInAppMessaging causing the error: + // Can't create handler inside thread Thread[pool-3-thread-1,5,main] that has not called Looper.prepare() + // at com.google.firebase.inappmessaging.internal.ForegroundNotifier.(ForegroundNotifier.java:61) + try { + Looper.prepare() + } catch (e: Exception) { + // do nothing + } + + initializeAppRequest.authDomain?.let { + customAuthDomain[appName] = it + } + + val context = applicationContext ?: throw IllegalStateException("Application context is null") + val firebaseApp = FirebaseApp.initializeApp(context, options, appName) + val response = firebaseAppToMap(firebaseApp) + callback(Result.success(response)) + } catch (e: Exception) { + callback(Result.failure(e)) + } + } + } + + override fun initializeCore(callback: (Result>) -> Unit) { + cachedThreadPool.execute { + try { + if (!coreInitialized) { + coreInitialized = true + } else { + Tasks.await(FlutterFirebasePluginRegistry.didReinitializeFirebaseCore()) + } + + val context = applicationContext ?: throw IllegalStateException("Application context is null") + val firebaseApps = FirebaseApp.getApps(context) + val firebaseAppsList = firebaseApps.map { firebaseApp -> + firebaseAppToMap(firebaseApp) + } + + callback(Result.success(firebaseAppsList)) + } catch (e: Exception) { + callback(Result.failure(e)) + } + } + } + + override fun optionsFromResource(callback: (Result) -> Unit) { + cachedThreadPool.execute { + try { + val context = applicationContext ?: throw IllegalStateException("Application context is null") + val options = FirebaseOptions.fromResource(context) + if (options == null) { + callback(Result.failure( + Exception("Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.") + )) + return@execute + } + callback(Result.success(firebaseOptionsToMap(options))) + } catch (e: Exception) { + callback(Result.failure(e)) + } + } + } + + override fun setAutomaticDataCollectionEnabled( + appName: String, + enabled: Boolean, + callback: (Result) -> Unit + ) { + cachedThreadPool.execute { + try { + val firebaseApp = FirebaseApp.getInstance(appName) + firebaseApp.setDataCollectionDefaultEnabled(enabled) + callback(Result.success(Unit)) + } catch (e: Exception) { + callback(Result.failure(e)) + } + } + } + + override fun setAutomaticResourceManagementEnabled( + appName: String, + enabled: Boolean, + callback: (Result) -> Unit + ) { + // Unsupported on Android - just succeed + callback(Result.success(Unit)) + } + + override fun delete(appName: String, callback: (Result) -> Unit) { + cachedThreadPool.execute { + try { + val firebaseApp = FirebaseApp.getInstance(appName) + try { + firebaseApp.delete() + } catch (appNotFoundException: IllegalStateException) { + // Ignore app not found exceptions. + } + callback(Result.success(Unit)) + } catch (e: Exception) { + callback(Result.failure(e)) + } + } + } + + companion object { + @JvmField + val customAuthDomain: MutableMap = mutableMapOf() + } +} diff --git a/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebaseCoreRegistrar.kt b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebaseCoreRegistrar.kt new file mode 100644 index 000000000000..4f732c10b913 --- /dev/null +++ b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebaseCoreRegistrar.kt @@ -0,0 +1,20 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.firebase.core + +import androidx.annotation.Keep +import com.google.firebase.components.Component +import com.google.firebase.components.ComponentRegistrar +import com.google.firebase.platforminfo.LibraryVersionComponent + +@Keep +class FlutterFirebaseCoreRegistrar : ComponentRegistrar { + override fun getComponents(): List> { + return listOf( + LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION) + ) + } +} + diff --git a/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebasePlugin.kt b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebasePlugin.kt new file mode 100644 index 000000000000..054b673dfa9c --- /dev/null +++ b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebasePlugin.kt @@ -0,0 +1,38 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +package io.flutter.plugins.firebase.core + +import androidx.annotation.Keep +import com.google.android.gms.tasks.Task +import com.google.firebase.FirebaseApp +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + +@Keep +interface FlutterFirebasePlugin { + /** + * FlutterFire plugins implementing FlutterFirebasePlugin must provide this method to provide it's + * constants that are initialized during FirebaseCore.initializeApp in Dart. + * + * @param firebaseApp The Firebase App that the plugin should return constants for. + * @return A task returning the discovered constants for the plugin for the provided Firebase App. + */ + fun getPluginConstantsForFirebaseApp(firebaseApp: FirebaseApp): Task> + + /** + * FlutterFire plugins implementing FlutterFirebasePlugin should provide this method to be + * notified when FirebaseCore#initializeCore was called again (first time is ignored). + * + * This can be used by plugins to know when they might need to cleanup previous resources + * between Hot Restarts as `initializeCore` can only be called once in Dart. + */ + fun didReinitializeFirebaseCore(): Task + + companion object { + // A shared ExecutorService used by all FlutterFire Plugins for their GMS Tasks. + @JvmField + val cachedThreadPool: ExecutorService = Executors.newCachedThreadPool() + } +} + diff --git a/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebasePluginRegistry.kt b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebasePluginRegistry.kt new file mode 100644 index 000000000000..11f05f25ea6f --- /dev/null +++ b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/FlutterFirebasePluginRegistry.kt @@ -0,0 +1,87 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +package io.flutter.plugins.firebase.core + +import androidx.annotation.Keep +import com.google.android.gms.tasks.Task +import com.google.android.gms.tasks.TaskCompletionSource +import com.google.android.gms.tasks.Tasks +import com.google.firebase.FirebaseApp +import io.flutter.plugins.firebase.core.FlutterFirebasePlugin.Companion.cachedThreadPool +import java.util.WeakHashMap + +@Keep +object FlutterFirebasePluginRegistry { + + private val registeredPlugins: MutableMap = WeakHashMap() + + /** + * Register a Flutter Firebase plugin with the Firebase plugin registry. + * + * @param channelName The MethodChannel name for the plugin to be registered, for example: + * `plugins.flutter.io/firebase_core` + * @param flutterFirebasePlugin A FlutterPlugin that implements FlutterFirebasePlugin. + */ + @JvmStatic + fun registerPlugin(channelName: String, flutterFirebasePlugin: FlutterFirebasePlugin) { + registeredPlugins[channelName] = flutterFirebasePlugin + } + + /** + * Each FlutterFire plugin implementing FlutterFirebasePlugin provides this method allowing it's + * constants to be initialized during FirebaseCore.initializeApp in Dart. Here we call this method + * on each of the registered plugins and gather their constants for use in Dart. + * + * @param firebaseApp The Firebase App that the plugin should return constants for. + * @return A task returning the discovered constants for each plugin (using channelName as the Map + * key) for the provided Firebase App. + */ + @JvmStatic + internal fun getPluginConstantsForFirebaseApp(firebaseApp: FirebaseApp): Task> { + val taskCompletionSource = TaskCompletionSource>() + + cachedThreadPool.execute { + try { + val pluginConstants = mutableMapOf() + + for ((channelName, plugin) in registeredPlugins) { + pluginConstants[channelName] = Tasks.await(plugin.getPluginConstantsForFirebaseApp(firebaseApp)) + } + + taskCompletionSource.setResult(pluginConstants) + } catch (e: Exception) { + taskCompletionSource.setException(e) + } + } + + return taskCompletionSource.task + } + + /** + * Each FlutterFire plugin implementing this method are notified that FirebaseCore#initializeCore + * was called again. + * + * This is used by plugins to know if they need to cleanup previous resources between Hot + * Restarts as `initializeCore` can only be called once in Dart. + */ + @JvmStatic + internal fun didReinitializeFirebaseCore(): Task { + val taskCompletionSource = TaskCompletionSource() + + cachedThreadPool.execute { + try { + for ((_, plugin) in registeredPlugins) { + Tasks.await(plugin.didReinitializeFirebaseCore()) + } + + taskCompletionSource.setResult(null) + } catch (e: Exception) { + taskCompletionSource.setException(e) + } + } + + return taskCompletionSource.task + } +} + diff --git a/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.kt b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.kt new file mode 100644 index 000000000000..e1db1270af05 --- /dev/null +++ b/packages/firebase_core/firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.kt @@ -0,0 +1,370 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// Autogenerated from Pigeon (v25.3.2), do not edit directly. +// See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") + +package io.flutter.plugins.firebase.core + +import android.util.Log +import io.flutter.plugin.common.BasicMessageChannel +import io.flutter.plugin.common.BinaryMessenger +import io.flutter.plugin.common.EventChannel +import io.flutter.plugin.common.MessageCodec +import io.flutter.plugin.common.StandardMethodCodec +import io.flutter.plugin.common.StandardMessageCodec +import java.io.ByteArrayOutputStream +import java.nio.ByteBuffer +private object GeneratedAndroidFirebaseCorePigeonUtils { + + fun wrapResult(result: Any?): List { + return listOf(result) + } + + fun wrapError(exception: Throwable): List { + return if (exception is GeneratedAndroidFirebaseCoreError) { + listOf( + exception.code, + exception.message, + exception.details + ) + } else { + listOf( + exception.javaClass.simpleName, + exception.toString(), + "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) + ) + } + } + fun deepEquals(a: Any?, b: Any?): Boolean { + if (a is ByteArray && b is ByteArray) { + return a.contentEquals(b) + } + if (a is IntArray && b is IntArray) { + return a.contentEquals(b) + } + if (a is LongArray && b is LongArray) { + return a.contentEquals(b) + } + if (a is DoubleArray && b is DoubleArray) { + return a.contentEquals(b) + } + if (a is Array<*> && b is Array<*>) { + return a.size == b.size && + a.indices.all{ deepEquals(a[it], b[it]) } + } + if (a is List<*> && b is List<*>) { + return a.size == b.size && + a.indices.all{ deepEquals(a[it], b[it]) } + } + if (a is Map<*, *> && b is Map<*, *>) { + return a.size == b.size && a.all { + (b as Map).containsKey(it.key) && + deepEquals(it.value, b[it.key]) + } + } + return a == b + } + +} + +/** + * Error class for passing custom error details to Flutter via a thrown PlatformException. + * @property code The error code. + * @property message The error message. + * @property details The error details. Must be a datatype supported by the api codec. + */ +class GeneratedAndroidFirebaseCoreError ( + val code: String, + override val message: String? = null, + val details: Any? = null +) : Throwable() + +/** Generated class from Pigeon that represents data sent in messages. */ +data class CoreFirebaseOptions ( + val apiKey: String, + val appId: String, + val messagingSenderId: String, + val projectId: String, + val authDomain: String? = null, + val databaseURL: String? = null, + val storageBucket: String? = null, + val measurementId: String? = null, + val trackingId: String? = null, + val deepLinkURLScheme: String? = null, + val androidClientId: String? = null, + val iosClientId: String? = null, + val iosBundleId: String? = null, + val appGroupId: String? = null +) + { + companion object { + fun fromList(pigeonVar_list: List): CoreFirebaseOptions { + val apiKey = pigeonVar_list[0] as String + val appId = pigeonVar_list[1] as String + val messagingSenderId = pigeonVar_list[2] as String + val projectId = pigeonVar_list[3] as String + val authDomain = pigeonVar_list[4] as String? + val databaseURL = pigeonVar_list[5] as String? + val storageBucket = pigeonVar_list[6] as String? + val measurementId = pigeonVar_list[7] as String? + val trackingId = pigeonVar_list[8] as String? + val deepLinkURLScheme = pigeonVar_list[9] as String? + val androidClientId = pigeonVar_list[10] as String? + val iosClientId = pigeonVar_list[11] as String? + val iosBundleId = pigeonVar_list[12] as String? + val appGroupId = pigeonVar_list[13] as String? + return CoreFirebaseOptions(apiKey, appId, messagingSenderId, projectId, authDomain, databaseURL, storageBucket, measurementId, trackingId, deepLinkURLScheme, androidClientId, iosClientId, iosBundleId, appGroupId) + } + } + fun toList(): List { + return listOf( + apiKey, + appId, + messagingSenderId, + projectId, + authDomain, + databaseURL, + storageBucket, + measurementId, + trackingId, + deepLinkURLScheme, + androidClientId, + iosClientId, + iosBundleId, + appGroupId, + ) + } + override fun equals(other: Any?): Boolean { + if (other !is CoreFirebaseOptions) { + return false + } + if (this === other) { + return true + } + return GeneratedAndroidFirebaseCorePigeonUtils.deepEquals(toList(), other.toList()) } + + override fun hashCode(): Int = toList().hashCode() +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class CoreInitializeResponse ( + val name: String, + val options: CoreFirebaseOptions, + val isAutomaticDataCollectionEnabled: Boolean? = null, + val pluginConstants: Map +) + { + companion object { + fun fromList(pigeonVar_list: List): CoreInitializeResponse { + val name = pigeonVar_list[0] as String + val options = pigeonVar_list[1] as CoreFirebaseOptions + val isAutomaticDataCollectionEnabled = pigeonVar_list[2] as Boolean? + val pluginConstants = pigeonVar_list[3] as Map + return CoreInitializeResponse(name, options, isAutomaticDataCollectionEnabled, pluginConstants) + } + } + fun toList(): List { + return listOf( + name, + options, + isAutomaticDataCollectionEnabled, + pluginConstants, + ) + } + override fun equals(other: Any?): Boolean { + if (other !is CoreInitializeResponse) { + return false + } + if (this === other) { + return true + } + return GeneratedAndroidFirebaseCorePigeonUtils.deepEquals(toList(), other.toList()) } + + override fun hashCode(): Int = toList().hashCode() +} +private open class GeneratedAndroidFirebaseCorePigeonCodec : StandardMessageCodec() { + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return when (type) { + 129.toByte() -> { + return (readValue(buffer) as? List)?.let { + CoreFirebaseOptions.fromList(it) + } + } + 130.toByte() -> { + return (readValue(buffer) as? List)?.let { + CoreInitializeResponse.fromList(it) + } + } + else -> super.readValueOfType(type, buffer) + } + } + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + when (value) { + is CoreFirebaseOptions -> { + stream.write(129) + writeValue(stream, value.toList()) + } + is CoreInitializeResponse -> { + stream.write(130) + writeValue(stream, value.toList()) + } + else -> super.writeValue(stream, value) + } + } +} + + +/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ +interface FirebaseCoreHostApi { + fun initializeApp(appName: String, initializeAppRequest: CoreFirebaseOptions, callback: (Result) -> Unit) + fun initializeCore(callback: (Result>) -> Unit) + fun optionsFromResource(callback: (Result) -> Unit) + + companion object { + /** The codec used by FirebaseCoreHostApi. */ + val codec: MessageCodec by lazy { + GeneratedAndroidFirebaseCorePigeonCodec() + } + /** Sets up an instance of `FirebaseCoreHostApi` to handle messages through the `binaryMessenger`. */ + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: FirebaseCoreHostApi?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeApp$separatedMessageChannelSuffix", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val appNameArg = args[0] as String + val initializeAppRequestArg = args[1] as CoreFirebaseOptions + api.initializeApp(appNameArg, initializeAppRequestArg) { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapError(error)) + } else { + val data = result.getOrNull() + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapResult(data)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore$separatedMessageChannelSuffix", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + api.initializeCore{ result: Result> -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapError(error)) + } else { + val data = result.getOrNull() + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapResult(data)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.optionsFromResource$separatedMessageChannelSuffix", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + api.optionsFromResource{ result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapError(error)) + } else { + val data = result.getOrNull() + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapResult(data)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + } + } +} +/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ +interface FirebaseAppHostApi { + fun setAutomaticDataCollectionEnabled(appName: String, enabled: Boolean, callback: (Result) -> Unit) + fun setAutomaticResourceManagementEnabled(appName: String, enabled: Boolean, callback: (Result) -> Unit) + fun delete(appName: String, callback: (Result) -> Unit) + + companion object { + /** The codec used by FirebaseAppHostApi. */ + val codec: MessageCodec by lazy { + GeneratedAndroidFirebaseCorePigeonCodec() + } + /** Sets up an instance of `FirebaseAppHostApi` to handle messages through the `binaryMessenger`. */ + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: FirebaseAppHostApi?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.setAutomaticDataCollectionEnabled$separatedMessageChannelSuffix", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val appNameArg = args[0] as String + val enabledArg = args[1] as Boolean + api.setAutomaticDataCollectionEnabled(appNameArg, enabledArg) { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapError(error)) + } else { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapResult(null)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.setAutomaticResourceManagementEnabled$separatedMessageChannelSuffix", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val appNameArg = args[0] as String + val enabledArg = args[1] as Boolean + api.setAutomaticResourceManagementEnabled(appNameArg, enabledArg) { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapError(error)) + } else { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapResult(null)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.delete$separatedMessageChannelSuffix", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val appNameArg = args[0] as String + api.delete(appNameArg) { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapError(error)) + } else { + reply.reply(GeneratedAndroidFirebaseCorePigeonUtils.wrapResult(null)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + } + } +} diff --git a/packages/firebase_core/firebase_core/example/android/app/build.gradle b/packages/firebase_core/firebase_core/example/android/app/build.gradle index d2ebd42da7b2..3d06527a23e2 100644 --- a/packages/firebase_core/firebase_core/example/android/app/build.gradle +++ b/packages/firebase_core/firebase_core/example/android/app/build.gradle @@ -45,7 +45,7 @@ android { applicationId = "io.flutter.plugins.firebasecoreexample" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdk = 23 + minSdkVersion = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = flutterVersionCode.toInteger() versionName = flutterVersionName diff --git a/packages/firebase_core/firebase_core/ios/firebase_core.podspec b/packages/firebase_core/firebase_core/ios/firebase_core.podspec index b29fb36140db..1b52ba32a950 100644 --- a/packages/firebase_core/firebase_core/ios/firebase_core.podspec +++ b/packages/firebase_core/firebase_core/ios/firebase_core.podspec @@ -24,10 +24,11 @@ Pod::Spec.new do |s| s.license = { :file => '../LICENSE' } s.authors = 'The Chromium Authors' s.source = { :path => '.' } - s.source_files = 'firebase_core/Sources/firebase_core/**/*.{h,m}' - s.public_header_files = 'firebase_core/Sources/firebase_core/include/**/*.h' + s.source_files = 'firebase_core/Sources/firebase_core/**/*.swift' + s.public_header_files = [] s.ios.deployment_target = '15.0' + s.swift_version = '5.0' # Flutter dependencies s.dependency 'Flutter' diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift b/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift index 33f81b0a0e7d..9e422bf4d7d4 100644 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Package.swift @@ -68,7 +68,6 @@ func loadFirebaseSDKVersion() throws -> String { let library_version_string: String let firebase_sdk_version_string: String -let shared_spm_tag = "-firebase-core-swift" do { library_version_string = try loadPubspecVersion() @@ -81,12 +80,6 @@ guard let firebase_sdk_version = Version(firebase_sdk_version_string) else { fatalError("Invalid Firebase SDK version: \(firebase_sdk_version_string)") } -// TODO: - we can try using existing firebase_core tag once flutterfire/Package.swift is part of release cycle -// but I don't think it'll work as Swift versioning requires version-[tag name] -guard let shared_spm_version = Version("\(library_version_string)\(shared_spm_tag)") else { - fatalError("Invalid firebase_core version: \(library_version_string)\(shared_spm_tag)") -} - let package = Package( name: "firebase_core", platforms: [ @@ -97,7 +90,6 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/firebase/firebase-ios-sdk", from: firebase_sdk_version), - .package(url: "https://github.com/firebase/flutterfire", exact: shared_spm_version), ], targets: [ .target( @@ -105,26 +97,9 @@ let package = Package( dependencies: [ // No product for firebase-core so we pull in the smallest one .product(name: "FirebaseInstallations", package: "firebase-ios-sdk"), - .product(name: "firebase-core-shared", package: "flutterfire"), - ], - exclude: [ - // These are now pulled in as a remote dependency from FlutterFire repo - "FLTFirebaseCorePlugin.m", - "FLTFirebasePlugin.m", - "FLTFirebasePluginRegistry.m", - "messages.g.m", - "include/firebase_core/FLTFirebaseCorePlugin.h", - "include/firebase_core/messages.g.h", - "include/firebase_core/FLTFirebasePlugin.h", - "include/firebase_core/FLTFirebasePluginRegistry.h", ], resources: [ .process("Resources"), - ], - cSettings: [ - .headerSearchPath("include/firebase_core"), - .define("LIBRARY_VERSION", to: "\"\(library_version_string)\""), - .define("LIBRARY_NAME", to: "\"flutter-fire-core\""), ] ), ] diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m deleted file mode 100644 index 23b3f7b9433b..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if __has_include("include/firebase_core/FLTFirebaseCorePlugin.h") -#import "include/firebase_core/FLTFirebaseCorePlugin.h" -#else -#import "include/FLTFirebaseCorePlugin.h" -#endif - -#if __has_include("include/firebase_core/FLTFirebasePluginRegistry.h") -#import "include/firebase_core/FLTFirebasePluginRegistry.h" -#else -#import "include/FLTFirebasePluginRegistry.h" -#endif - -#if __has_include("include/firebase_core/messages.g.h") -#import "include/firebase_core/messages.g.h" -#else -#import "include/messages.g.h" -#endif - -@implementation FLTFirebaseCorePlugin { - BOOL _coreInitialized; -} - -#pragma mark - FlutterPlugin - -+ (void)registerWithRegistrar:(NSObject *)registrar { - FLTFirebaseCorePlugin *sharedInstance = [self sharedInstance]; -#if TARGET_OS_OSX -#else - [registrar publish:sharedInstance]; -#endif - SetUpFirebaseCoreHostApi(registrar.messenger, sharedInstance); - SetUpFirebaseAppHostApi(registrar.messenger, sharedInstance); -} - -// Returns a singleton instance of the Firebase Core plugin. -+ (instancetype)sharedInstance { - static dispatch_once_t onceToken; - static FLTFirebaseCorePlugin *instance; - - dispatch_once(&onceToken, ^{ - instance = [[FLTFirebaseCorePlugin alloc] init]; - // Register with the Flutter Firebase plugin registry. - [[FLTFirebasePluginRegistry sharedInstance] registerFirebasePlugin:instance]; - - // Initialize default Firebase app, but only if the plist file options - // exist. - // - If it is missing then there is no default app discovered in Dart and - // Dart throws an error. - // - Without this the iOS/MacOS app would crash immediately on calling - // [FIRApp configure] without - // providing helpful context about the crash to the user. - // - // Default app exists check is for backwards compatibility of legacy - // FlutterFire plugins that call [FIRApp configure]; themselves internally. - FIROptions *options = [FIROptions defaultOptions]; - if (options != nil && [FIRApp allApps][@"__FIRAPP_DEFAULT"] == nil) { - [FIRApp configureWithOptions:options]; - } - }); - - return instance; -} - -static NSMutableDictionary *customAuthDomains; - -// Initialize static properties - -+ (void)initialize { - if (self == [FLTFirebaseCorePlugin self]) { - customAuthDomains = [[NSMutableDictionary alloc] init]; - } -} - -+ (NSString *)getCustomDomain:(NSString *)appName { - return customAuthDomains[appName]; -} - -#pragma mark - Helpers - -- (CoreFirebaseOptions *)optionsFromFIROptions:(FIROptions *)options { - CoreFirebaseOptions *pigeonOptions = [CoreFirebaseOptions alloc]; - pigeonOptions.apiKey = (id)options.APIKey ?: [NSNull null]; - pigeonOptions.appId = (id)options.googleAppID ?: [NSNull null]; - pigeonOptions.messagingSenderId = (id)options.GCMSenderID ?: [NSNull null]; - pigeonOptions.projectId = (id)options.projectID ?: [NSNull null]; - pigeonOptions.databaseURL = (id)options.databaseURL ?: [NSNull null]; - pigeonOptions.storageBucket = (id)options.storageBucket ?: [NSNull null]; - pigeonOptions.deepLinkURLScheme = [NSNull null]; - pigeonOptions.iosBundleId = (id)options.bundleID ?: [NSNull null]; - pigeonOptions.iosClientId = (id)options.clientID ?: [NSNull null]; - pigeonOptions.appGroupId = (id)options.appGroupID ?: [NSNull null]; - return pigeonOptions; -} - -- (CoreInitializeResponse *)initializeResponseFromFIRApp:(FIRApp *)firebaseApp { - NSString *appNameDart = [FLTFirebasePlugin firebaseAppNameFromIosName:firebaseApp.name]; - CoreInitializeResponse *response = [CoreInitializeResponse alloc]; - response.name = appNameDart; - response.options = [self optionsFromFIROptions:firebaseApp.options]; - response.isAutomaticDataCollectionEnabled = @(firebaseApp.isDataCollectionDefaultEnabled); - response.pluginConstants = - [[FLTFirebasePluginRegistry sharedInstance] pluginConstantsForFIRApp:firebaseApp]; - - return response; -} - -#pragma mark - FLTFirebasePlugin - -- (void)didReinitializeFirebaseCore:(void (^)(void))completion { - completion(); -} - -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *)firebase_app { - return @{}; -} - -- (NSString *_Nonnull)firebaseLibraryName { - return @LIBRARY_NAME; -} - -- (NSString *_Nonnull)firebaseLibraryVersion { - return @LIBRARY_VERSION; -} - -- (NSString *_Nonnull)flutterChannelName { - // The pigeon channel depends on each function - return @"dev.flutter.pigeon.FirebaseCoreHostApi.initializeApp"; -} - -#pragma mark - API - -- (void)initializeAppAppName:(nonnull NSString *)appName - initializeAppRequest:(nonnull CoreFirebaseOptions *)initializeAppRequest - completion:(nonnull void (^)(CoreInitializeResponse *_Nullable, - FlutterError *_Nullable))completion { - NSString *appNameIos = [FLTFirebasePlugin firebaseAppNameFromDartName:appName]; - - if ([FLTFirebasePlugin firebaseAppNamed:appNameIos]) { - completion([self initializeResponseFromFIRApp:[FLTFirebasePlugin firebaseAppNamed:appNameIos]], - nil); - return; - } - - NSString *appId = initializeAppRequest.appId; - NSString *messagingSenderId = initializeAppRequest.messagingSenderId; - FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:appId - GCMSenderID:messagingSenderId]; - - options.APIKey = initializeAppRequest.apiKey; - options.projectID = initializeAppRequest.projectId; - - // kFirebaseOptionsDatabaseUrl - if (![initializeAppRequest.databaseURL isEqual:[NSNull null]]) { - options.databaseURL = initializeAppRequest.databaseURL; - } - - // kFirebaseOptionsStorageBucket - if (![options.storageBucket isEqual:[NSNull null]]) { - options.storageBucket = initializeAppRequest.storageBucket; - } - - // kFirebaseOptionsIosBundleId - if (![initializeAppRequest.iosBundleId isEqual:[NSNull null]]) { - options.bundleID = initializeAppRequest.iosBundleId; - } - - // kFirebaseOptionsIosClientId - if (![initializeAppRequest.iosClientId isEqual:[NSNull null]]) { - options.clientID = initializeAppRequest.iosClientId; - } - - // kFirebaseOptionsAppGroupId - if (![initializeAppRequest.appGroupId isEqual:[NSNull null]]) { - options.appGroupID = initializeAppRequest.appGroupId; - } - - if (initializeAppRequest.authDomain != nil) { - customAuthDomains[appNameIos] = initializeAppRequest.authDomain; - } - - [FIRApp configureWithName:appNameIos options:options]; - - completion([self initializeResponseFromFIRApp:[FIRApp appNamed:appNameIos]], nil); -} - -- (void)initializeCoreWithCompletion:(nonnull void (^)(NSArray *_Nullable, - FlutterError *_Nullable))completion { - void (^initializeCoreBlock)(void) = ^void() { - NSDictionary *firebaseApps = [FIRApp allApps]; - NSMutableArray *firebaseAppsArray = [NSMutableArray arrayWithCapacity:firebaseApps.count]; - - for (NSString *appName in firebaseApps) { - FIRApp *firebaseApp = firebaseApps[appName]; - [firebaseAppsArray addObject:[self initializeResponseFromFIRApp:firebaseApp]]; - } - - completion(firebaseAppsArray, nil); - }; - - if (!_coreInitialized) { - _coreInitialized = YES; - initializeCoreBlock(); - } else { - [[FLTFirebasePluginRegistry sharedInstance] didReinitializeFirebaseCore:initializeCoreBlock]; - } -} - -- (void)optionsFromResourceWithCompletion:(nonnull void (^)(CoreFirebaseOptions *_Nullable, - FlutterError *_Nullable))completion { - // Unsupported on iOS/MacOS. - completion(nil, nil); -} - -- (void)deleteAppName:(nonnull NSString *)appName - completion:(nonnull void (^)(FlutterError *_Nullable))completion { - FIRApp *firebaseApp = [FLTFirebasePlugin firebaseAppNamed:appName]; - - if (firebaseApp) { - [firebaseApp deleteApp:^(BOOL success) { - if (success) { - completion(nil); - } else { - completion([FlutterError errorWithCode:@"delete-failed" - message:@"Failed to delete a Firebase app instance." - details:nil]); - } - }]; - } else { - completion(nil); - } -} - -- (void)setAutomaticDataCollectionEnabledAppName:(nonnull NSString *)appName - enabled:(BOOL)enabled - completion: - (nonnull void (^)(FlutterError *_Nullable))completion { - FIRApp *firebaseApp = [FLTFirebasePlugin firebaseAppNamed:appName]; - if (firebaseApp) { - [firebaseApp setDataCollectionDefaultEnabled:enabled]; - } - - completion(nil); -} - -- (void)setAutomaticResourceManagementEnabledAppName:(nonnull NSString *)appName - enabled:(BOOL)enabled - completion:(nonnull void (^)(FlutterError *_Nullable)) - completion { - // Unsupported on iOS/MacOS. - completion(nil); -} - -@end diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift new file mode 100644 index 000000000000..84d92bacaa26 --- /dev/null +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift @@ -0,0 +1,235 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import FirebaseCore +import Foundation + +#if os(macOS) + import FlutterMacOS +#else + import Flutter +#endif + +@objc public class FLTFirebaseCorePlugin: FLTFirebasePluginHelper, FlutterPlugin, FLTFirebasePlugin, + FirebaseCoreHostApi, FirebaseAppHostApi { + private var coreInitialized = false + private static var customAuthDomains: [String: String] = [:] + + // MARK: - FlutterPlugin + + @objc public static func register(with registrar: FlutterPluginRegistrar) { + let instance = sharedInstance() + #if os(macOS) + let messenger = registrar.messenger + #else + registrar.publish(instance) + let messenger = registrar.messenger() + #endif + FirebaseCoreHostApiSetup.setUp(binaryMessenger: messenger, api: instance) + FirebaseAppHostApiSetup.setUp(binaryMessenger: messenger, api: instance) + } + + // Returns a singleton instance of the Firebase Core plugin. + @objc public static func sharedInstance() -> FLTFirebaseCorePlugin { + enum Singleton { + static let instance: FLTFirebaseCorePlugin = { + let instance = FLTFirebaseCorePlugin() + // Register with the Flutter Firebase plugin registry. + FLTFirebasePluginRegistry.shared.registerFirebasePlugin(instance) + + // Initialize default Firebase app, but only if the plist file options exist. + // - If it is missing then there is no default app discovered in Dart and + // Dart throws an error. + // - Without this the iOS/MacOS app would crash immediately on calling + // FirebaseApp.configure() without providing helpful context about the crash to the user. + // + // Default app exists check is for backwards compatibility of legacy + // FlutterFire plugins that call FirebaseApp.configure() themselves internally. + if let options = FirebaseOptions.defaultOptions(), + FirebaseApp.app(name: kFIRDefaultAppNameIOS) == nil { + FirebaseApp.configure(options: options) + } + + return instance + }() + } + return Singleton.instance + } + + @objc public static func getCustomDomain(_ appName: String) -> String? { + customAuthDomains[appName] + } + + // MARK: - Helpers + + private func optionsFromFIROptions(_ options: FirebaseOptions) -> CoreFirebaseOptions { + CoreFirebaseOptions( + apiKey: options.apiKey ?? "", + appId: options.googleAppID, + messagingSenderId: options.gcmSenderID, + projectId: options.projectID ?? "", + databaseURL: options.databaseURL, + storageBucket: options.storageBucket, + iosClientId: options.clientID, + iosBundleId: options.bundleID, + appGroupId: options.appGroupID + ) + } + + private func initializeResponse(from firebaseApp: FirebaseApp) -> CoreInitializeResponse { + let appNameDart = FLTFirebasePluginHelper.firebaseAppName(fromIosName: firebaseApp.name) + return CoreInitializeResponse( + name: appNameDart, + options: optionsFromFIROptions(firebaseApp.options), + isAutomaticDataCollectionEnabled: firebaseApp.isDataCollectionDefaultEnabled, + pluginConstants: FLTFirebasePluginRegistry.shared.pluginConstants(forFIRApp: firebaseApp) + ) + } + + // MARK: - FLTFirebasePlugin + + @objc public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { + completion() + } + + @objc public func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] { + [:] + } + + @objc public var firebaseLibraryName: String { + "flutter-fire-core" + } + + @objc public var firebaseLibraryVersion: String { + // TODO: Get version from Package.swift or build configuration + "4.2.0" + } + + @objc public var flutterChannelName: String { + // The pigeon channel depends on each function + "dev.flutter.pigeon.FirebaseCoreHostApi.initializeApp" + } + + // MARK: - API + + func initializeApp(appName: String, + initializeAppRequest: CoreFirebaseOptions, + completion: @escaping (Result) -> Void) { + let appNameIos = FLTFirebasePluginHelper.firebaseAppName(fromDartName: appName) + + if let existingApp = FLTFirebasePluginHelper.firebaseApp(named: appName) { + completion(.success(initializeResponse(from: existingApp))) + return + } + + let appId = initializeAppRequest.appId + let messagingSenderId = initializeAppRequest.messagingSenderId + + let options = FirebaseOptions(googleAppID: appId, gcmSenderID: messagingSenderId) + options.apiKey = initializeAppRequest.apiKey + options.projectID = initializeAppRequest.projectId + + if let databaseURL = initializeAppRequest.databaseURL { + options.databaseURL = databaseURL + } + + if let storageBucket = initializeAppRequest.storageBucket { + options.storageBucket = storageBucket + } + + if let iosBundleId = initializeAppRequest.iosBundleId { + options.bundleID = iosBundleId + } + + if let iosClientId = initializeAppRequest.iosClientId { + options.clientID = iosClientId + } + + if let appGroupId = initializeAppRequest.appGroupId { + options.appGroupID = appGroupId + } + + if let authDomain = initializeAppRequest.authDomain { + FLTFirebaseCorePlugin.customAuthDomains[appNameIos] = authDomain + } + + FirebaseApp.configure(name: appNameIos, options: options) + + if let firebaseApp = FirebaseApp.app(name: appNameIos) { + completion(.success(initializeResponse(from: firebaseApp))) + } else { + completion(.failure(NSError(domain: "FLTFirebaseCore", + code: -1, + userInfo: [ + NSLocalizedDescriptionKey: "Failed to configure Firebase app", + ]))) + } + } + + func initializeCore(completion: @escaping (Result<[CoreInitializeResponse], Error>) -> Void) { + let initializeCoreBlock: () -> Void = { + var firebaseAppsArray: [CoreInitializeResponse] = [] + + if let firebaseApps = FirebaseApp.allApps { + for (_, firebaseApp) in firebaseApps { + firebaseAppsArray.append(self.initializeResponse(from: firebaseApp)) + } + } + + completion(.success(firebaseAppsArray)) + } + + if !coreInitialized { + coreInitialized = true + initializeCoreBlock() + } else { + FLTFirebasePluginRegistry.shared.didReinitializeFirebaseCore(completion: initializeCoreBlock) + } + } + + func optionsFromResource(completion: @escaping (Result) -> Void) { + // Unsupported on iOS/MacOS - return empty options with minimal required fields + completion(.success(CoreFirebaseOptions( + apiKey: "", + appId: "", + messagingSenderId: "", + projectId: "" + ))) + } + + func delete(appName: String, completion: @escaping (Result) -> Void) { + guard let firebaseApp = FLTFirebasePluginHelper.firebaseApp(named: appName) else { + completion(.success(())) + return + } + + firebaseApp.delete { success in + if success { + completion(.success(())) + } else { + completion(.failure(NSError(domain: "FLTFirebaseCore", + code: -1, + userInfo: [ + NSLocalizedDescriptionKey: "Failed to delete a Firebase app instance.", + ]))) + } + } + } + + func setAutomaticDataCollectionEnabled(appName: String, + enabled: Bool, + completion: @escaping (Result) -> Void) { + if let firebaseApp = FLTFirebasePluginHelper.firebaseApp(named: appName) { + firebaseApp.isDataCollectionDefaultEnabled = enabled + } + completion(.success(())) + } + + func setAutomaticResourceManagementEnabled(appName: String, + enabled: Bool, + completion: @escaping (Result) -> Void) { + // Unsupported on iOS/MacOS. + completion(.success(())) + } +} diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m deleted file mode 100644 index 2b00388f7f1c..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if __has_include("include/firebase_core/FLTFirebasePlugin.h") -#import "include/firebase_core/FLTFirebasePlugin.h" -#else -#import "include/FLTFirebasePlugin.h" -#endif - -// Firebase default app name. -NSString *_Nonnull const kFIRDefaultAppNameIOS = @"__FIRAPP_DEFAULT"; -NSString *_Nonnull const kFIRDefaultAppNameDart = @"[DEFAULT]"; - -@interface FLTFirebaseMethodCallResult () -@property(readwrite, nonatomic) FLTFirebaseMethodCallErrorBlock error; -@property(readwrite, nonatomic) FLTFirebaseMethodCallSuccessBlock success; -@end -@implementation FLTFirebaseMethodCallResult - -+ (instancetype)createWithSuccess:(FLTFirebaseMethodCallSuccessBlock)successBlock - andErrorBlock:(FLTFirebaseMethodCallErrorBlock)errorBlock { - FLTFirebaseMethodCallResult *methodCallResult = [[FLTFirebaseMethodCallResult alloc] init]; - methodCallResult.error = errorBlock; - methodCallResult.success = successBlock; - return methodCallResult; -} - -@end - -@implementation FLTFirebasePlugin -+ (FlutterError *_Nonnull)createFlutterErrorFromCode:(NSString *_Nonnull)code - message:(NSString *_Nonnull)message - optionalDetails:(NSDictionary *_Nullable)details - andOptionalNSError:(NSError *_Nullable)error { - NSMutableDictionary *detailsDict = [NSMutableDictionary dictionaryWithDictionary:details ?: @{}]; - if (error != nil) { - detailsDict[@"nativeErrorCode"] = [@(error.code) stringValue]; - detailsDict[@"nativeErrorMessage"] = error.localizedDescription; - } - return [FlutterError errorWithCode:code message:message details:detailsDict]; -} - -+ (NSString *)firebaseAppNameFromDartName:(NSString *_Nonnull)appName { - NSString *appNameIOS = appName; - if ([kFIRDefaultAppNameDart isEqualToString:appName]) { - appNameIOS = kFIRDefaultAppNameIOS; - } - return appNameIOS; -} - -+ (NSString *_Nonnull)firebaseAppNameFromIosName:(NSString *_Nonnull)appName { - NSString *appNameDart = appName; - if ([kFIRDefaultAppNameIOS isEqualToString:appName]) { - appNameDart = kFIRDefaultAppNameDart; - } - return appNameDart; -} - -+ (FIRApp *_Nullable)firebaseAppNamed:(NSString *_Nonnull)appName { - return [FIRApp allApps][[self firebaseAppNameFromDartName:appName]]; -} -@end diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift new file mode 100644 index 000000000000..3a61be4a330c --- /dev/null +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift @@ -0,0 +1,126 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import FirebaseCore +import Foundation + +#if os(macOS) + import FlutterMacOS +#else + import Flutter +#endif + +// Firebase default app names +let kFIRDefaultAppNameIOS = "__FIRAPP_DEFAULT" +let kFIRDefaultAppNameDart = "[DEFAULT]" + +/// Block that is capable of sending a success response to a method call operation. +public typealias FLTFirebaseMethodCallSuccessBlock = (Any?) -> Void + +/// Block that is capable of sending an error response to a method call operation. +public typealias FLTFirebaseMethodCallErrorBlock = (String?, String?, [String: Any]?, Error?) + -> Void + +/// A protocol that all FlutterFire plugins should implement. +@objc public protocol FLTFirebasePlugin { + /// FlutterFire plugins implementing FLTFirebasePlugin should provide this method + /// to be notified when FirebaseCore#initializeCore was called again (first time is ignored). + /// + /// This can be used by plugins to know when they might need to cleanup previous + /// resources between Hot Restarts as `initializeCore` can only be called once in Dart. + @objc func didReinitializeFirebaseCore(completion: @escaping () -> Void) + + /// FlutterFire plugins implementing FLTFirebasePlugin must provide this method + /// to provide it's constants that are initialized during FirebaseCore.initializeApp in Dart. + /// + /// - Parameter firebaseApp: The Firebase App that the plugin should return constants for. + /// - Returns: A dictionary of constants for the plugin. + @objc func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] + + /// The Firebase library name of the plugin, used by FirebaseApp.registerLibrary + /// to register this plugin with the Firebase backend. + @objc var firebaseLibraryName: String { get } + + /// The Firebase library version of the plugin, used by FirebaseApp.registerLibrary + /// to register this plugin with the Firebase backend. + @objc var firebaseLibraryVersion: String { get } + + /// FlutterFire plugins implementing FLTFirebasePlugin must provide this method + /// to provide its main method channel name, used by FirebaseCore.initializeApp + /// in Dart to identify constants specific to a plugin. + @objc var flutterChannelName: String { get } +} + +/// An interface representing a returned result from a Flutter Method Call. +@objc public class FLTFirebaseMethodCallResult: NSObject { + @objc public let success: FLTFirebaseMethodCallSuccessBlock + @objc public let error: FLTFirebaseMethodCallErrorBlock + + private init(success: @escaping FLTFirebaseMethodCallSuccessBlock, + error: @escaping FLTFirebaseMethodCallErrorBlock) { + self.success = success + self.error = error + super.init() + } + + @objc public static func create(success: @escaping FLTFirebaseMethodCallSuccessBlock, + andErrorBlock error: @escaping FLTFirebaseMethodCallErrorBlock) + -> FLTFirebaseMethodCallResult { + FLTFirebaseMethodCallResult(success: success, error: error) + } +} + +@objc open class FLTFirebasePluginHelper: NSObject { + /// Creates a standardized instance of FlutterError using the values returned + /// through FLTFirebaseMethodCallErrorBlock. + /// + /// - Parameters: + /// - code: Error Code. + /// - message: Error Message. + /// - details: Optional dictionary of additional key/values to return to Dart. + /// - error: Optional Error that this error relates to. + /// - Returns: FlutterError instance. + @objc public static func createFlutterError(code: String, + message: String, + optionalDetails details: [String: Any]?, + andOptionalError error: Error?) -> FlutterError { + var detailsDict = details ?? [:] + if let error = error as NSError? { + detailsDict["nativeErrorCode"] = String(error.code) + detailsDict["nativeErrorMessage"] = error.localizedDescription + } + return FlutterError(code: code, message: message, details: detailsDict) + } + + /// Converts the '[DEFAULT]' app name used in dart and other SDKs to the + /// '__FIRAPP_DEFAULT' iOS equivalent. + /// + /// If name is not '[DEFAULT]' then just returns the same name that was passed in. + /// + /// - Parameter appName: The name of the Firebase App. + /// - Returns: The iOS-compatible app name. + @objc public static func firebaseAppName(fromDartName appName: String) -> String { + appName == kFIRDefaultAppNameDart ? kFIRDefaultAppNameIOS : appName + } + + /// Converts the '__FIRAPP_DEFAULT' app name used in iOS to '[DEFAULT]' - used in + /// Dart & other SDKs. + /// + /// If name is not '__FIRAPP_DEFAULT' then just returns the same name that was passed in. + /// + /// - Parameter appName: The name of the Firebase App. + /// - Returns: The Dart-compatible app name. + @objc public static func firebaseAppName(fromIosName appName: String) -> String { + appName == kFIRDefaultAppNameIOS ? kFIRDefaultAppNameDart : appName + } + + /// Retrieves a FirebaseApp instance based on the app name provided from Dart code. + /// + /// - Parameter appName: The name of the Firebase App. + /// - Returns: FirebaseApp instance, or nil if it doesn't exist. + @objc public static func firebaseApp(named appName: String) -> FirebaseApp? { + let iosName = firebaseAppName(fromDartName: appName) + return FirebaseApp.app(name: iosName) + } +} diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m deleted file mode 100644 index a6f2f5657aae..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if __has_include("include/firebase_core/FLTFirebasePluginRegistry.h") -#import "include/firebase_core/FLTFirebasePluginRegistry.h" -#else -#import "include/FLTFirebasePluginRegistry.h" -#endif - -#if __has_include() -#import -#define REGISTER_LIB -#elif __has_include() -#import -#define REGISTER_LIB -#endif - -@implementation FLTFirebasePluginRegistry { - NSMutableDictionary> *registeredPlugins; -} - -- (instancetype)init { - self = [super init]; - if (self) { - registeredPlugins = [NSMutableDictionary dictionary]; - } - return self; -} - -+ (instancetype)sharedInstance { - static dispatch_once_t onceToken; - static FLTFirebasePluginRegistry *instance; - - dispatch_once(&onceToken, ^{ - instance = [[FLTFirebasePluginRegistry alloc] init]; - }); - - return instance; -} - -- (void)registerFirebasePlugin:(id)firebasePlugin { - // Register the library with the Firebase backend. -#ifdef REGISTER_LIB - [FIRApp registerLibrary:[firebasePlugin firebaseLibraryName] - withVersion:[firebasePlugin firebaseLibraryVersion]]; -#endif - // Store the plugin delegate for later usage. - registeredPlugins[[firebasePlugin flutterChannelName]] = firebasePlugin; -} - -- (NSDictionary *)pluginConstantsForFIRApp:(FIRApp *)firebaseApp { - NSString *pluginFlutterChannelName; - NSMutableDictionary *pluginConstants = [NSMutableDictionary dictionary]; - - for (pluginFlutterChannelName in registeredPlugins) { - pluginConstants[pluginFlutterChannelName] = - [registeredPlugins[pluginFlutterChannelName] pluginConstantsForFIRApp:firebaseApp]; - } - - return pluginConstants; -} - -- (void)didReinitializeFirebaseCore:(void (^_Nonnull)(void))completion { - __block int pluginsCompleted = 0; - NSUInteger pluginsCount = [self->registeredPlugins allKeys].count; - void (^allPluginsCompletion)(void) = ^void() { - pluginsCompleted++; - if (pluginsCompleted == pluginsCount) { - completion(); - } - }; - - for (NSString *pluginFlutterChannelName in registeredPlugins) { - [registeredPlugins[pluginFlutterChannelName] didReinitializeFirebaseCore:allPluginsCompletion]; - } -} - -@end diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.swift b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.swift new file mode 100644 index 000000000000..9629f7128a78 --- /dev/null +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.swift @@ -0,0 +1,90 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import FirebaseCore +import Foundation + +#if canImport(FirebaseCoreInternal) + import FirebaseCoreInternal +#endif + +@objc public class FLTFirebasePluginRegistry: NSObject { + private var registeredPlugins: [String: FLTFirebasePlugin] = [:] + + override private init() { + super.init() + } + + /// Get the shared singleton instance of the plugin registry. + /// + /// - Returns: Shared FLTFirebasePluginRegistry instance. + @objc public static let shared = FLTFirebasePluginRegistry() + + /// For compatibility with Objective-C code + @objc public static func sharedInstance() -> FLTFirebasePluginRegistry { + shared + } + + /// Register a FlutterFire plugin with the plugin registry. + /// + /// Plugins must conform to the FLTFirebasePlugin protocol. + /// + /// - Parameter firebasePlugin: The plugin conforming to FLTFirebasePlugin protocol. + @objc public func registerFirebasePlugin(_ firebasePlugin: FLTFirebasePlugin) { + // Register the library with the Firebase backend using runtime checking + // for compatibility across different Firebase SDK versions. + if FirebaseApp.responds(to: NSSelectorFromString("registerLibrary:withVersion:")) { + FirebaseApp.perform( + NSSelectorFromString("registerLibrary:withVersion:"), + with: firebasePlugin.firebaseLibraryName, + with: firebasePlugin.firebaseLibraryVersion + ) + } + + // Store the plugin delegate for later usage. + registeredPlugins[firebasePlugin.flutterChannelName] = firebasePlugin + } + + /// Each FlutterFire plugin implementing FLTFirebasePlugin provides this method, + /// allowing its constants to be initialized during FirebaseCore.initializeApp in Dart. + /// Here we call this method on each of the registered plugins and gather their constants for use + /// in Dart. + /// + /// Constants for specific plugins are stored using the Flutter plugins channel name as the key. + /// + /// - Parameter firebaseApp: Firebase App instance these constants relate to. + /// - Returns: Dictionary of plugins and their constants. + @objc public func pluginConstants(forFIRApp firebaseApp: FirebaseApp) -> [String: Any] { + var pluginConstants: [String: Any] = [:] + + for (channelName, plugin) in registeredPlugins { + pluginConstants[channelName] = plugin.pluginConstants(for: firebaseApp) + } + + return pluginConstants + } + + /// Each FlutterFire plugin implementing this method are notified that + /// FirebaseCore#initializeCore was called again. + /// + /// This is used by plugins to know if they need to cleanup previous + /// resources between Hot Restarts as `initializeCore` can only be called once in Dart. + /// + /// - Parameter completion: Completion handler called when all plugins have completed. + @objc public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { + var pluginsCompleted = 0 + let pluginsCount = registeredPlugins.count + + let allPluginsCompletion: () -> Void = { + pluginsCompleted += 1 + if pluginsCompleted == pluginsCount { + completion() + } + } + + for plugin in registeredPlugins.values { + plugin.didReinitializeFirebaseCore(completion: allPluginsCompletion) + } + } +} diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/dummy.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/dummy.m deleted file mode 100644 index b26e56855988..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/dummy.m +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright 2023, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/.gitkeep b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/.gitkeep deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h deleted file mode 100644 index accb377c7b46..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#import "FLTFirebasePlugin.h" -#if __has_include("include/messages.g.h") -#import "include/messages.g.h" -#else -#import "messages.g.h" -#endif - -@interface FLTFirebaseCorePlugin - : FLTFirebasePlugin - -+ (NSString *)getCustomDomain:(NSString *)appName; - -@end diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h deleted file mode 100644 index 63e4290b4516..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Note: Don't use umbrella header here - will cause a -// build -// failure on MacOS builds (Flutter MacOS uses Swift) when this file is -// included in other Flutter plugins like Firestore with an error of -// "Include of non-modular header inside framework module". -#import -#import -#import - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -/** - * Block that is capable of sending a success response to a method call - * operation. Use this for returning success data to a Method call. - */ -typedef void (^FLTFirebaseMethodCallSuccessBlock)(id _Nullable result); - -/** - * Block that is capable of sending an error response to a method call - * operation. Use this for returning error information to a Method call. - */ -typedef void (^FLTFirebaseMethodCallErrorBlock)(NSString *_Nullable code, - NSString *_Nullable message, - NSDictionary *_Nullable details, - NSError *_Nullable error); - -/** - * A protocol that all FlutterFire plugins should implement. - */ -@protocol FLTFirebasePlugin -/** - * FlutterFire plugins implementing FLTFirebasePlugin should provide this method - * to be notified when FirebaseCore#initializeCore was called again (first time - * is ignored). - * - * This can be used by plugins to know when they might need to cleanup previous - * resources between Hot Restarts as `initializeCore` can only be called once in - * Dart. - */ -@required -- (void)didReinitializeFirebaseCore:(void (^_Nonnull)(void))completion; - -/** - * FlutterFire plugins implementing FLTFirebasePlugin must provide this method - * to provide it's constants that are initialized during - * FirebaseCore.initializeApp in Dart. - * - * @param registrar A helper providing application context and methods for - * registering callbacks. - */ -@required -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *_Nonnull)firebaseApp; - -/** - * The Firebase library name of the plugin, used by - * [FIRApp registerLibrary:firebaseLibraryName withVersion:] to - * register this plugin with the Firebase backend. - * - * Usually this is provided by the 'LIBRARY_NAME' preprocessor definition - * defined in the plugins .podspec file. - */ -@required -- (NSString *_Nonnull)firebaseLibraryName; - -/** - * The Firebase library version of the plugin, used by - * FIRApp registerLibrary:withVersion:firebaseLibraryVersion] to - * register this plugin with the Firebase backend. - * - * Usually this is provided by the 'LIBRARY_VERSION' preprocessor definition - * defined in the plugins .podspec file. - */ -@required -- (NSString *_Nonnull)firebaseLibraryVersion; - -/** - * FlutterFire plugins implementing FLTFirebasePlugin must provide this method - * to provide its main method channel name, used by FirebaseCore.initializeApp - * in Dart to identify constants specific to a plugin. - */ -@required -- (NSString *_Nonnull)flutterChannelName; -@end - -/** - * An interface represent a returned result from a Flutter Method Call. - */ -@interface FLTFirebaseMethodCallResult : NSObject -+ (instancetype _Nonnull)createWithSuccess:(FLTFirebaseMethodCallSuccessBlock _Nonnull)successBlock - andErrorBlock:(FLTFirebaseMethodCallErrorBlock _Nonnull)errorBlock; - -/** - * Submit a result indicating a successful method call. - * - * E.g.: `result.success(nil);` - */ -@property(readonly, nonatomic) FLTFirebaseMethodCallSuccessBlock _Nonnull success; - -/** - * Submit a result indicating a failed method call. - * - * E.g.: `result.error(@"code", @"message", nil);` - */ -@property(readonly, nonatomic) FLTFirebaseMethodCallErrorBlock _Nonnull error; - -@end - -@interface FLTFirebasePlugin : NSObject -/** - * Creates a standardized instance of FlutterError using the values returned - * through FLTFirebaseMethodCallErrorBlock. - * - * @param code Error Code. - * @param message Error Message. - * @param details Optional dictionary of additional key/values to return to - * Dart. - * @param error Optional NSError that this error relates to. - * - * @return FlutterError - */ -+ (FlutterError *_Nonnull)createFlutterErrorFromCode:(NSString *_Nonnull)code - message:(NSString *_Nonnull)message - optionalDetails:(NSDictionary *_Nullable)details - andOptionalNSError:(NSError *_Nullable)error; - -/** - * Converts the '[DEFAULT]' app name used in dart and other SDKs to the - * '__FIRAPP_DEFAULT' iOS equivalent. - * - * If name is not '[DEFAULT]' then just returns the same name that was passed - * in. - * - * @param appName The name of the Firebase App. - * - * @return NSString - */ -+ (NSString *_Nonnull)firebaseAppNameFromDartName:(NSString *_Nonnull)appName; - -/** - * Converts the '__FIRAPP_DEFAULT' app name used in iOS to '[DEFAULT]' - used in - * Dart & other SDKs. - * - * If name is not '__FIRAPP_DEFAULT' then just returns the same name that was - * passed in. - * - * @param appName The name of the Firebase App. - * - * @return NSString - */ -+ (NSString *_Nonnull)firebaseAppNameFromIosName:(NSString *_Nonnull)appName; - -/** - * Retrieves a FIRApp instance based on the app name provided from Dart code. - * - * @param appName The name of the Firebase App. - * - * @return FIRApp - returns nil if Firebase app does not exist. - */ -+ (FIRApp *_Nullable)firebaseAppNamed:(NSString *_Nonnull)appName; -@end diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h deleted file mode 100644 index 17b454fc53e8..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import -#import "FLTFirebasePlugin.h" - -@interface FLTFirebasePluginRegistry : NSObject -/** - * Get the shared singleton instance of the plugin registry. - * - * @return FLTFirebasePluginRegistry - */ -+ (instancetype _Nonnull)sharedInstance; - -/** - * Register a FlutterFire plugin with the plugin registry. - * - * Plugins must conform to the FLTFirebasePlugin protocol. - * - * @param firebasePlugin id - */ -- (void)registerFirebasePlugin:(id _Nonnull)firebasePlugin; - -/** - * Each FlutterFire plugin implementing FLTFirebasePlugin provides this method, - * allowing it's constants to be initialized during FirebaseCore.initializeApp - * in Dart. Here we call this method on each of the registered plugins and - * gather their constants for use in Dart. - * - * Constants for specific plugins are stored using the Flutter plugins channel - * name as the key. - * - * @param firebaseApp FIRApp Firebase App instance these constants relate to. - * @return NSDictionary Dictionary of plugins and their constants. - */ -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *_Nonnull)firebaseApp; - -/** - * Each FlutterFire plugin implementing this method are notified that - * FirebaseCore#initializeCore was called again. - * - * This is used by plugins to know if they need to cleanup previous - * resources between Hot Restarts as `initializeCore` can only be called once in - * Dart. - */ -- (void)didReinitializeFirebaseCore:(void (^_Nonnull)(void))completion; -@end diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/dummy.h b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/dummy.h deleted file mode 100644 index b26e56855988..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/dummy.h +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright 2023, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h deleted file mode 100644 index cc06241e7cb1..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2023, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -// Autogenerated from Pigeon (v25.3.2), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -#import - -@protocol FlutterBinaryMessenger; -@protocol FlutterMessageCodec; -@class FlutterError; -@class FlutterStandardTypedData; - -NS_ASSUME_NONNULL_BEGIN - -@class CoreFirebaseOptions; -@class CoreInitializeResponse; - -@interface CoreFirebaseOptions : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithApiKey:(NSString *)apiKey - appId:(NSString *)appId - messagingSenderId:(NSString *)messagingSenderId - projectId:(NSString *)projectId - authDomain:(nullable NSString *)authDomain - databaseURL:(nullable NSString *)databaseURL - storageBucket:(nullable NSString *)storageBucket - measurementId:(nullable NSString *)measurementId - trackingId:(nullable NSString *)trackingId - deepLinkURLScheme:(nullable NSString *)deepLinkURLScheme - androidClientId:(nullable NSString *)androidClientId - iosClientId:(nullable NSString *)iosClientId - iosBundleId:(nullable NSString *)iosBundleId - appGroupId:(nullable NSString *)appGroupId; -@property(nonatomic, copy) NSString *apiKey; -@property(nonatomic, copy) NSString *appId; -@property(nonatomic, copy) NSString *messagingSenderId; -@property(nonatomic, copy) NSString *projectId; -@property(nonatomic, copy, nullable) NSString *authDomain; -@property(nonatomic, copy, nullable) NSString *databaseURL; -@property(nonatomic, copy, nullable) NSString *storageBucket; -@property(nonatomic, copy, nullable) NSString *measurementId; -@property(nonatomic, copy, nullable) NSString *trackingId; -@property(nonatomic, copy, nullable) NSString *deepLinkURLScheme; -@property(nonatomic, copy, nullable) NSString *androidClientId; -@property(nonatomic, copy, nullable) NSString *iosClientId; -@property(nonatomic, copy, nullable) NSString *iosBundleId; -@property(nonatomic, copy, nullable) NSString *appGroupId; -@end - -@interface CoreInitializeResponse : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithName:(NSString *)name - options:(CoreFirebaseOptions *)options - isAutomaticDataCollectionEnabled:(nullable NSNumber *)isAutomaticDataCollectionEnabled - pluginConstants:(NSDictionary *)pluginConstants; -@property(nonatomic, copy) NSString *name; -@property(nonatomic, strong) CoreFirebaseOptions *options; -@property(nonatomic, strong, nullable) NSNumber *isAutomaticDataCollectionEnabled; -@property(nonatomic, copy) NSDictionary *pluginConstants; -@end - -/// The codec used by all APIs. -NSObject *nullGetMessagesCodec(void); - -@protocol FirebaseCoreHostApi -- (void)initializeAppAppName:(NSString *)appName - initializeAppRequest:(CoreFirebaseOptions *)initializeAppRequest - completion:(void (^)(CoreInitializeResponse *_Nullable, - FlutterError *_Nullable))completion; -- (void)initializeCoreWithCompletion:(void (^)(NSArray *_Nullable, - FlutterError *_Nullable))completion; -- (void)optionsFromResourceWithCompletion:(void (^)(CoreFirebaseOptions *_Nullable, - FlutterError *_Nullable))completion; -@end - -extern void SetUpFirebaseCoreHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFirebaseCoreHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -@protocol FirebaseAppHostApi -- (void)setAutomaticDataCollectionEnabledAppName:(NSString *)appName - enabled:(BOOL)enabled - completion:(void (^)(FlutterError *_Nullable))completion; -- (void)setAutomaticResourceManagementEnabledAppName:(NSString *)appName - enabled:(BOOL)enabled - completion:(void (^)(FlutterError *_Nullable))completion; -- (void)deleteAppName:(NSString *)appName completion:(void (^)(FlutterError *_Nullable))completion; -@end - -extern void SetUpFirebaseAppHostApi(id binaryMessenger, - NSObject *_Nullable api); - -extern void SetUpFirebaseAppHostApiWithSuffix(id binaryMessenger, - NSObject *_Nullable api, - NSString *messageChannelSuffix); - -NS_ASSUME_NONNULL_END diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m deleted file mode 100644 index ff9ac9933bc0..000000000000 --- a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m +++ /dev/null @@ -1,389 +0,0 @@ -// Copyright 2023, the Chromium project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. -// Autogenerated from Pigeon (v25.3.2), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -#if __has_include("include/firebase_core/messages.g.h") -#import "include/firebase_core/messages.g.h" -#else -#import "include/messages.g.h" -#endif - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#if !__has_feature(objc_arc) -#error File requires ARC to be enabled. -#endif - -static NSArray *wrapResult(id result, FlutterError *error) { - if (error) { - return @[ - error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] - ]; - } - return @[ result ?: [NSNull null] ]; -} - -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { - id result = array[key]; - return (result == [NSNull null]) ? nil : result; -} - -@interface CoreFirebaseOptions () -+ (CoreFirebaseOptions *)fromList:(NSArray *)list; -+ (nullable CoreFirebaseOptions *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@interface CoreInitializeResponse () -+ (CoreInitializeResponse *)fromList:(NSArray *)list; -+ (nullable CoreInitializeResponse *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@implementation CoreFirebaseOptions -+ (instancetype)makeWithApiKey:(NSString *)apiKey - appId:(NSString *)appId - messagingSenderId:(NSString *)messagingSenderId - projectId:(NSString *)projectId - authDomain:(nullable NSString *)authDomain - databaseURL:(nullable NSString *)databaseURL - storageBucket:(nullable NSString *)storageBucket - measurementId:(nullable NSString *)measurementId - trackingId:(nullable NSString *)trackingId - deepLinkURLScheme:(nullable NSString *)deepLinkURLScheme - androidClientId:(nullable NSString *)androidClientId - iosClientId:(nullable NSString *)iosClientId - iosBundleId:(nullable NSString *)iosBundleId - appGroupId:(nullable NSString *)appGroupId { - CoreFirebaseOptions *pigeonResult = [[CoreFirebaseOptions alloc] init]; - pigeonResult.apiKey = apiKey; - pigeonResult.appId = appId; - pigeonResult.messagingSenderId = messagingSenderId; - pigeonResult.projectId = projectId; - pigeonResult.authDomain = authDomain; - pigeonResult.databaseURL = databaseURL; - pigeonResult.storageBucket = storageBucket; - pigeonResult.measurementId = measurementId; - pigeonResult.trackingId = trackingId; - pigeonResult.deepLinkURLScheme = deepLinkURLScheme; - pigeonResult.androidClientId = androidClientId; - pigeonResult.iosClientId = iosClientId; - pigeonResult.iosBundleId = iosBundleId; - pigeonResult.appGroupId = appGroupId; - return pigeonResult; -} -+ (CoreFirebaseOptions *)fromList:(NSArray *)list { - CoreFirebaseOptions *pigeonResult = [[CoreFirebaseOptions alloc] init]; - pigeonResult.apiKey = GetNullableObjectAtIndex(list, 0); - pigeonResult.appId = GetNullableObjectAtIndex(list, 1); - pigeonResult.messagingSenderId = GetNullableObjectAtIndex(list, 2); - pigeonResult.projectId = GetNullableObjectAtIndex(list, 3); - pigeonResult.authDomain = GetNullableObjectAtIndex(list, 4); - pigeonResult.databaseURL = GetNullableObjectAtIndex(list, 5); - pigeonResult.storageBucket = GetNullableObjectAtIndex(list, 6); - pigeonResult.measurementId = GetNullableObjectAtIndex(list, 7); - pigeonResult.trackingId = GetNullableObjectAtIndex(list, 8); - pigeonResult.deepLinkURLScheme = GetNullableObjectAtIndex(list, 9); - pigeonResult.androidClientId = GetNullableObjectAtIndex(list, 10); - pigeonResult.iosClientId = GetNullableObjectAtIndex(list, 11); - pigeonResult.iosBundleId = GetNullableObjectAtIndex(list, 12); - pigeonResult.appGroupId = GetNullableObjectAtIndex(list, 13); - return pigeonResult; -} -+ (nullable CoreFirebaseOptions *)nullableFromList:(NSArray *)list { - return (list) ? [CoreFirebaseOptions fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.apiKey ?: [NSNull null], - self.appId ?: [NSNull null], - self.messagingSenderId ?: [NSNull null], - self.projectId ?: [NSNull null], - self.authDomain ?: [NSNull null], - self.databaseURL ?: [NSNull null], - self.storageBucket ?: [NSNull null], - self.measurementId ?: [NSNull null], - self.trackingId ?: [NSNull null], - self.deepLinkURLScheme ?: [NSNull null], - self.androidClientId ?: [NSNull null], - self.iosClientId ?: [NSNull null], - self.iosBundleId ?: [NSNull null], - self.appGroupId ?: [NSNull null], - ]; -} -@end - -@implementation CoreInitializeResponse -+ (instancetype)makeWithName:(NSString *)name - options:(CoreFirebaseOptions *)options - isAutomaticDataCollectionEnabled:(nullable NSNumber *)isAutomaticDataCollectionEnabled - pluginConstants:(NSDictionary *)pluginConstants { - CoreInitializeResponse *pigeonResult = [[CoreInitializeResponse alloc] init]; - pigeonResult.name = name; - pigeonResult.options = options; - pigeonResult.isAutomaticDataCollectionEnabled = isAutomaticDataCollectionEnabled; - pigeonResult.pluginConstants = pluginConstants; - return pigeonResult; -} -+ (CoreInitializeResponse *)fromList:(NSArray *)list { - CoreInitializeResponse *pigeonResult = [[CoreInitializeResponse alloc] init]; - pigeonResult.name = GetNullableObjectAtIndex(list, 0); - pigeonResult.options = GetNullableObjectAtIndex(list, 1); - pigeonResult.isAutomaticDataCollectionEnabled = GetNullableObjectAtIndex(list, 2); - pigeonResult.pluginConstants = GetNullableObjectAtIndex(list, 3); - return pigeonResult; -} -+ (nullable CoreInitializeResponse *)nullableFromList:(NSArray *)list { - return (list) ? [CoreInitializeResponse fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - self.name ?: [NSNull null], - self.options ?: [NSNull null], - self.isAutomaticDataCollectionEnabled ?: [NSNull null], - self.pluginConstants ?: [NSNull null], - ]; -} -@end - -@interface nullMessagesPigeonCodecReader : FlutterStandardReader -@end -@implementation nullMessagesPigeonCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 129: - return [CoreFirebaseOptions fromList:[self readValue]]; - case 130: - return [CoreInitializeResponse fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface nullMessagesPigeonCodecWriter : FlutterStandardWriter -@end -@implementation nullMessagesPigeonCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[CoreFirebaseOptions class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[CoreInitializeResponse class]]) { - [self writeByte:130]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface nullMessagesPigeonCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation nullMessagesPigeonCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[nullMessagesPigeonCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[nullMessagesPigeonCodecReader alloc] initWithData:data]; -} -@end - -NSObject *nullGetMessagesCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - nullMessagesPigeonCodecReaderWriter *readerWriter = - [[nullMessagesPigeonCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} -void SetUpFirebaseCoreHostApi(id binaryMessenger, - NSObject *api) { - SetUpFirebaseCoreHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFirebaseCoreHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.firebase_core_platform_" - @"interface.FirebaseCoreHostApi.initializeApp", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:nullGetMessagesCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(initializeAppAppName: - initializeAppRequest:completion:)], - @"FirebaseCoreHostApi api (%@) doesn't respond to " - @"@selector(initializeAppAppName:initializeAppRequest:completion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSString *arg_appName = GetNullableObjectAtIndex(args, 0); - CoreFirebaseOptions *arg_initializeAppRequest = GetNullableObjectAtIndex(args, 1); - [api initializeAppAppName:arg_appName - initializeAppRequest:arg_initializeAppRequest - completion:^(CoreInitializeResponse *_Nullable output, - FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.firebase_core_platform_" - @"interface.FirebaseCoreHostApi.initializeCore", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:nullGetMessagesCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(initializeCoreWithCompletion:)], - @"FirebaseCoreHostApi api (%@) doesn't respond to " - @"@selector(initializeCoreWithCompletion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - [api initializeCoreWithCompletion:^(NSArray *_Nullable output, - FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString - stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.firebase_core_platform_interface." - @"FirebaseCoreHostApi.optionsFromResource", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:nullGetMessagesCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(optionsFromResourceWithCompletion:)], - @"FirebaseCoreHostApi api (%@) doesn't respond to " - @"@selector(optionsFromResourceWithCompletion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - [api optionsFromResourceWithCompletion:^(CoreFirebaseOptions *_Nullable output, - FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} -void SetUpFirebaseAppHostApi(id binaryMessenger, - NSObject *api) { - SetUpFirebaseAppHostApiWithSuffix(binaryMessenger, api, @""); -} - -void SetUpFirebaseAppHostApiWithSuffix(id binaryMessenger, - NSObject *api, - NSString *messageChannelSuffix) { - messageChannelSuffix = messageChannelSuffix.length > 0 - ? [NSString stringWithFormat:@".%@", messageChannelSuffix] - : @""; - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName: - [NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.firebase_core_platform_interface." - @"FirebaseAppHostApi.setAutomaticDataCollectionEnabled", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:nullGetMessagesCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setAutomaticDataCollectionEnabledAppName:enabled:completion:)], - @"FirebaseAppHostApi api (%@) doesn't respond to " - @"@selector(setAutomaticDataCollectionEnabledAppName:enabled:completion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSString *arg_appName = GetNullableObjectAtIndex(args, 0); - BOOL arg_enabled = [GetNullableObjectAtIndex(args, 1) boolValue]; - [api setAutomaticDataCollectionEnabledAppName:arg_appName - enabled:arg_enabled - completion:^(FlutterError *_Nullable error) { - callback(wrapResult(nil, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat: - @"%@%@", - @"dev.flutter.pigeon.firebase_core_platform_interface." - @"FirebaseAppHostApi.setAutomaticResourceManagementEnabled", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:nullGetMessagesCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector - (setAutomaticResourceManagementEnabledAppName:enabled:completion:)], - @"FirebaseAppHostApi api (%@) doesn't respond to " - @"@selector(setAutomaticResourceManagementEnabledAppName:enabled:completion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSString *arg_appName = GetNullableObjectAtIndex(args, 0); - BOOL arg_enabled = [GetNullableObjectAtIndex(args, 1) boolValue]; - [api setAutomaticResourceManagementEnabledAppName:arg_appName - enabled:arg_enabled - completion:^(FlutterError *_Nullable error) { - callback(wrapResult(nil, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:[NSString stringWithFormat:@"%@%@", - @"dev.flutter.pigeon.firebase_core_platform_" - @"interface.FirebaseAppHostApi.delete", - messageChannelSuffix] - binaryMessenger:binaryMessenger - codec:nullGetMessagesCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector(deleteAppName:completion:)], - @"FirebaseAppHostApi api (%@) doesn't respond to @selector(deleteAppName:completion:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSString *arg_appName = GetNullableObjectAtIndex(args, 0); - [api deleteAppName:arg_appName - completion:^(FlutterError *_Nullable error) { - callback(wrapResult(nil, error)); - }]; - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} diff --git a/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.swift b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.swift new file mode 100644 index 000000000000..8068b28371ed --- /dev/null +++ b/packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.swift @@ -0,0 +1,459 @@ +// Copyright 2023, the Chromium project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +// Autogenerated from Pigeon (v25.3.2), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Sendable? + + init(code: String, message: String?, details: Sendable?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + +private func wrapResult(_ result: Any?) -> [Any?] { + [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details, + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)", + ] +} + +private func isNullish(_ value: Any?) -> Bool { + value is NSNull || value == nil +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +func deepEqualsmessages(_ lhs: Any?, _ rhs: Any?) -> Bool { + let cleanLhs = nilOrValue(lhs) as Any? + let cleanRhs = nilOrValue(rhs) as Any? + switch (cleanLhs, cleanRhs) { + case (nil, nil): + return true + + case (nil, _), (_, nil): + return false + + case is (Void, Void): + return true + + case let (cleanLhsHashable, cleanRhsHashable) as (AnyHashable, AnyHashable): + return cleanLhsHashable == cleanRhsHashable + + case let (cleanLhsArray, cleanRhsArray) as ([Any?], [Any?]): + guard cleanLhsArray.count == cleanRhsArray.count else { return false } + for (index, element) in cleanLhsArray.enumerated() { + if !deepEqualsmessages(element, cleanRhsArray[index]) { + return false + } + } + return true + + case let (cleanLhsDictionary, cleanRhsDictionary) as ([AnyHashable: Any?], [AnyHashable: Any?]): + guard cleanLhsDictionary.count == cleanRhsDictionary.count else { return false } + for (key, cleanLhsValue) in cleanLhsDictionary { + guard cleanRhsDictionary.index(forKey: key) != nil else { return false } + if !deepEqualsmessages(cleanLhsValue, cleanRhsDictionary[key]!) { + return false + } + } + return true + + default: + // Any other type shouldn't be able to be used with pigeon. File an issue if you find this to be + // untrue. + return false + } +} + +func deepHashmessages(value: Any?, hasher: inout Hasher) { + if let valueList = value as? [AnyHashable] { + for item in valueList { + deepHashmessages(value: item, hasher: &hasher) + } + return + } + + if let valueDict = value as? [AnyHashable: AnyHashable] { + for key in valueDict.keys { + hasher.combine(key) + deepHashmessages(value: valueDict[key]!, hasher: &hasher) + } + return + } + + if let hashableValue = value as? AnyHashable { + hasher.combine(hashableValue.hashValue) + } + + return hasher.combine(String(describing: value)) +} + +/// Generated class from Pigeon that represents data sent in messages. +struct CoreFirebaseOptions: Hashable { + var apiKey: String + var appId: String + var messagingSenderId: String + var projectId: String + var authDomain: String? + var databaseURL: String? + var storageBucket: String? + var measurementId: String? + var trackingId: String? + var deepLinkURLScheme: String? + var androidClientId: String? + var iosClientId: String? + var iosBundleId: String? + var appGroupId: String? + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> CoreFirebaseOptions? { + let apiKey = pigeonVar_list[0] as! String + let appId = pigeonVar_list[1] as! String + let messagingSenderId = pigeonVar_list[2] as! String + let projectId = pigeonVar_list[3] as! String + let authDomain: String? = nilOrValue(pigeonVar_list[4]) + let databaseURL: String? = nilOrValue(pigeonVar_list[5]) + let storageBucket: String? = nilOrValue(pigeonVar_list[6]) + let measurementId: String? = nilOrValue(pigeonVar_list[7]) + let trackingId: String? = nilOrValue(pigeonVar_list[8]) + let deepLinkURLScheme: String? = nilOrValue(pigeonVar_list[9]) + let androidClientId: String? = nilOrValue(pigeonVar_list[10]) + let iosClientId: String? = nilOrValue(pigeonVar_list[11]) + let iosBundleId: String? = nilOrValue(pigeonVar_list[12]) + let appGroupId: String? = nilOrValue(pigeonVar_list[13]) + + return CoreFirebaseOptions( + apiKey: apiKey, + appId: appId, + messagingSenderId: messagingSenderId, + projectId: projectId, + authDomain: authDomain, + databaseURL: databaseURL, + storageBucket: storageBucket, + measurementId: measurementId, + trackingId: trackingId, + deepLinkURLScheme: deepLinkURLScheme, + androidClientId: androidClientId, + iosClientId: iosClientId, + iosBundleId: iosBundleId, + appGroupId: appGroupId + ) + } + + func toList() -> [Any?] { + [ + apiKey, + appId, + messagingSenderId, + projectId, + authDomain, + databaseURL, + storageBucket, + measurementId, + trackingId, + deepLinkURLScheme, + androidClientId, + iosClientId, + iosBundleId, + appGroupId, + ] + } + + static func == (lhs: CoreFirebaseOptions, rhs: CoreFirebaseOptions) -> Bool { + deepEqualsmessages(lhs.toList(), rhs.toList()) + } + + func hash(into hasher: inout Hasher) { + deepHashmessages(value: toList(), hasher: &hasher) + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct CoreInitializeResponse: Hashable { + var name: String + var options: CoreFirebaseOptions + var isAutomaticDataCollectionEnabled: Bool? + var pluginConstants: [String?: Any?] + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> CoreInitializeResponse? { + let name = pigeonVar_list[0] as! String + let options = pigeonVar_list[1] as! CoreFirebaseOptions + let isAutomaticDataCollectionEnabled: Bool? = nilOrValue(pigeonVar_list[2]) + let pluginConstants = pigeonVar_list[3] as! [String?: Any?] + + return CoreInitializeResponse( + name: name, + options: options, + isAutomaticDataCollectionEnabled: isAutomaticDataCollectionEnabled, + pluginConstants: pluginConstants + ) + } + + func toList() -> [Any?] { + [ + name, + options, + isAutomaticDataCollectionEnabled, + pluginConstants, + ] + } + + static func == (lhs: CoreInitializeResponse, rhs: CoreInitializeResponse) -> Bool { + deepEqualsmessages(lhs.toList(), rhs.toList()) + } + + func hash(into hasher: inout Hasher) { + deepHashmessages(value: toList(), hasher: &hasher) + } +} + +private class MessagesPigeonCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 129: + return CoreFirebaseOptions.fromList(readValue() as! [Any?]) + case 130: + return CoreInitializeResponse.fromList(readValue() as! [Any?]) + default: + return super.readValue(ofType: type) + } + } +} + +private class MessagesPigeonCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? CoreFirebaseOptions { + super.writeByte(129) + super.writeValue(value.toList()) + } else if let value = value as? CoreInitializeResponse { + super.writeByte(130) + super.writeValue(value.toList()) + } else { + super.writeValue(value) + } + } +} + +private class MessagesPigeonCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + MessagesPigeonCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + MessagesPigeonCodecWriter(data: data) + } +} + +class MessagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = MessagesPigeonCodec(readerWriter: MessagesPigeonCodecReaderWriter()) +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol FirebaseCoreHostApi { + func initializeApp(appName: String, initializeAppRequest: CoreFirebaseOptions, + completion: @escaping (Result) -> Void) + func initializeCore(completion: @escaping (Result<[CoreInitializeResponse], Error>) -> Void) + func optionsFromResource(completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class FirebaseCoreHostApiSetup { + static var codec: FlutterStandardMessageCodec { MessagesPigeonCodec.shared } + /// Sets up an instance of `FirebaseCoreHostApi` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: FirebaseCoreHostApi?, + messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let initializeAppChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeApp\(channelSuffix)", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + initializeAppChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let appNameArg = args[0] as! String + let initializeAppRequestArg = args[1] as! CoreFirebaseOptions + api + .initializeApp(appName: appNameArg, + initializeAppRequest: initializeAppRequestArg) { result in + switch result { + case let .success(res): + reply(wrapResult(res)) + case let .failure(error): + reply(wrapError(error)) + } + } + } + } else { + initializeAppChannel.setMessageHandler(nil) + } + let initializeCoreChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.initializeCore\(channelSuffix)", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + initializeCoreChannel.setMessageHandler { _, reply in + api.initializeCore { result in + switch result { + case let .success(res): + reply(wrapResult(res)) + case let .failure(error): + reply(wrapError(error)) + } + } + } + } else { + initializeCoreChannel.setMessageHandler(nil) + } + let optionsFromResourceChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseCoreHostApi.optionsFromResource\(channelSuffix)", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + optionsFromResourceChannel.setMessageHandler { _, reply in + api.optionsFromResource { result in + switch result { + case let .success(res): + reply(wrapResult(res)) + case let .failure(error): + reply(wrapError(error)) + } + } + } + } else { + optionsFromResourceChannel.setMessageHandler(nil) + } + } +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol FirebaseAppHostApi { + func setAutomaticDataCollectionEnabled(appName: String, enabled: Bool, + completion: @escaping (Result) -> Void) + func setAutomaticResourceManagementEnabled(appName: String, enabled: Bool, + completion: @escaping (Result) -> Void) + func delete(appName: String, completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class FirebaseAppHostApiSetup { + static var codec: FlutterStandardMessageCodec { MessagesPigeonCodec.shared } + /// Sets up an instance of `FirebaseAppHostApi` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: FirebaseAppHostApi?, + messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let setAutomaticDataCollectionEnabledChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.setAutomaticDataCollectionEnabled\(channelSuffix)", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + setAutomaticDataCollectionEnabledChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let appNameArg = args[0] as! String + let enabledArg = args[1] as! Bool + api.setAutomaticDataCollectionEnabled(appName: appNameArg, enabled: enabledArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case let .failure(error): + reply(wrapError(error)) + } + } + } + } else { + setAutomaticDataCollectionEnabledChannel.setMessageHandler(nil) + } + let setAutomaticResourceManagementEnabledChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.setAutomaticResourceManagementEnabled\(channelSuffix)", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + setAutomaticResourceManagementEnabledChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let appNameArg = args[0] as! String + let enabledArg = args[1] as! Bool + api + .setAutomaticResourceManagementEnabled(appName: appNameArg, + enabled: enabledArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case let .failure(error): + reply(wrapError(error)) + } + } + } + } else { + setAutomaticResourceManagementEnabledChannel.setMessageHandler(nil) + } + let deleteChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.firebase_core_platform_interface.FirebaseAppHostApi.delete\(channelSuffix)", + binaryMessenger: binaryMessenger, + codec: codec + ) + if let api { + deleteChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let appNameArg = args[0] as! String + api.delete(appName: appNameArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case let .failure(error): + reply(wrapError(error)) + } + } + } + } else { + deleteChannel.setMessageHandler(nil) + } + } +} diff --git a/packages/firebase_core/firebase_core/macos/firebase_core.podspec b/packages/firebase_core/firebase_core/macos/firebase_core.podspec index 030602b6683b..db7ccf1ccdcc 100644 --- a/packages/firebase_core/firebase_core/macos/firebase_core.podspec +++ b/packages/firebase_core/firebase_core/macos/firebase_core.podspec @@ -42,10 +42,11 @@ Pod::Spec.new do |s| s.license = { :file => '../LICENSE' } s.authors = 'The Chromium Authors' s.source = { :path => '.' } - s.source_files = 'firebase_core/Sources/firebase_core/**/*.{h,m}' - s.public_header_files = 'firebase_core/Sources/firebase_core/include/**/*.h' + s.source_files = 'firebase_core/Sources/firebase_core/**/*.swift' + s.public_header_files = [] s.platform = :osx, '10.15' + s.swift_version = '5.0' # Flutter dependencies s.dependency 'FlutterMacOS' diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Package.swift b/packages/firebase_core/firebase_core/macos/firebase_core/Package.swift index 72866c18e400..789ff35a61ce 100644 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Package.swift +++ b/packages/firebase_core/firebase_core/macos/firebase_core/Package.swift @@ -70,7 +70,6 @@ func loadFirebaseSDKVersion() throws -> String { let library_version_string: String let firebase_sdk_version_string: String -let shared_spm_tag = "-firebase-core-swift" do { library_version_string = try loadPubspecVersion() @@ -83,12 +82,6 @@ guard let firebase_sdk_version = Version(firebase_sdk_version_string) else { fatalError("Invalid Firebase SDK version: \(firebase_sdk_version_string)") } -// TODO: - we can try using existing firebase_core tag once flutterfire/Package.swift is part of release cycle -// but I don't think it'll work as Swift versioning requires version-[tag name] -guard let shared_spm_version = Version("\(library_version_string)\(shared_spm_tag)") else { - fatalError("Invalid firebase_core version: \(library_version_string)\(shared_spm_tag)") -} - let package = Package( name: "firebase_core", platforms: [ @@ -99,7 +92,6 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/firebase/firebase-ios-sdk", from: firebase_sdk_version), - .package(url: "https://github.com/firebase/flutterfire", exact: shared_spm_version), ], targets: [ .target( @@ -107,26 +99,9 @@ let package = Package( dependencies: [ // No product for firebase-core so we pull in the smallest one .product(name: "FirebaseInstallations", package: "firebase-ios-sdk"), - .product(name: "firebase-core-shared", package: "flutterfire"), - ], - exclude: [ - // These are now pulled in as a remote dependency from FlutterFire repo - "FLTFirebaseCorePlugin.m", - "FLTFirebasePlugin.m", - "FLTFirebasePluginRegistry.m", - "messages.g.m", - "include/firebase_core/FLTFirebaseCorePlugin.h", - "include/firebase_core/messages.g.h", - "include/firebase_core/FLTFirebasePlugin.h", - "include/firebase_core/FLTFirebasePluginRegistry.h", ], resources: [ .process("Resources"), - ], - cSettings: [ - .headerSearchPath("include/firebase_core"), - .define("LIBRARY_VERSION", to: "\"\(library_version_string)\""), - .define("LIBRARY_NAME", to: "\"flutter-fire-core\""), ] ), ] diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m deleted file mode 120000 index d014e98d510f..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m +++ /dev/null @@ -1 +0,0 @@ -../../../../ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.m \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift new file mode 120000 index 000000000000..ecb9b8b96d5f --- /dev/null +++ b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift @@ -0,0 +1 @@ +../../../../ios/firebase_core/Sources/firebase_core/FLTFirebaseCorePlugin.swift \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m deleted file mode 120000 index e6ce8910e33c..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m +++ /dev/null @@ -1 +0,0 @@ -../../../../ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.m \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift new file mode 120000 index 000000000000..ff5477e8d0fe --- /dev/null +++ b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift @@ -0,0 +1 @@ +../../../../ios/firebase_core/Sources/firebase_core/FLTFirebasePlugin.swift \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m deleted file mode 120000 index 9c70b9506434..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m +++ /dev/null @@ -1 +0,0 @@ -../../../../ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.m \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.swift b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.swift new file mode 120000 index 000000000000..13e9c229c8cb --- /dev/null +++ b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.swift @@ -0,0 +1 @@ +../../../../ios/firebase_core/Sources/firebase_core/FLTFirebasePluginRegistry.swift \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h deleted file mode 120000 index b8c28eb5bd36..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../../ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebaseCorePlugin.h \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h deleted file mode 120000 index 18a8349f94be..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../../ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePlugin.h \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h deleted file mode 120000 index 17ebeb905b75..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../../ios/firebase_core/Sources/firebase_core/include/firebase_core/FLTFirebasePluginRegistry.h \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h deleted file mode 120000 index 77dd32416d53..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h +++ /dev/null @@ -1 +0,0 @@ -../../../../../../ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/messages.g.m b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/messages.g.m deleted file mode 120000 index 8c67a9cfd102..000000000000 --- a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/messages.g.m +++ /dev/null @@ -1 +0,0 @@ -../../../../ios/firebase_core/Sources/firebase_core/messages.g.m \ No newline at end of file diff --git a/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/messages.g.swift b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/messages.g.swift new file mode 120000 index 000000000000..a5d828734f88 --- /dev/null +++ b/packages/firebase_core/firebase_core/macos/firebase_core/Sources/firebase_core/messages.g.swift @@ -0,0 +1 @@ +../../../../ios/firebase_core/Sources/firebase_core/messages.g.swift \ No newline at end of file diff --git a/packages/firebase_core/firebase_core_platform_interface/pigeons/messages.dart b/packages/firebase_core/firebase_core_platform_interface/pigeons/messages.dart index 977270c87dc1..a615e87a9473 100644 --- a/packages/firebase_core/firebase_core_platform_interface/pigeons/messages.dart +++ b/packages/firebase_core/firebase_core_platform_interface/pigeons/messages.dart @@ -9,16 +9,14 @@ import 'package:pigeon/pigeon.dart'; dartOut: 'lib/src/pigeon/messages.pigeon.dart', // We export in the lib folder to expose the class to other packages. dartTestOut: 'lib/src/pigeon/test_api.dart', - javaOut: - '../firebase_core/android/src/main/java/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.java', - javaOptions: JavaOptions( + kotlinOut: + '../firebase_core/android/src/main/kotlin/io/flutter/plugins/firebase/core/GeneratedAndroidFirebaseCore.kt', + kotlinOptions: KotlinOptions( package: 'io.flutter.plugins.firebase.core', - className: 'GeneratedAndroidFirebaseCore', + errorClassName: 'GeneratedAndroidFirebaseCoreError', ), - objcHeaderOut: - '../firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h', - objcSourceOut: - '../firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.m', + swiftOut: + '../firebase_core/ios/firebase_core/Sources/firebase_core/messages.g.swift', cppHeaderOut: '../firebase_core/windows/messages.g.h', cppSourceOut: '../firebase_core/windows/messages.g.cpp', cppOptions: CppOptions(namespace: 'firebase_core_windows'), diff --git a/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/FLTFirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/FLTFirebaseCrashlyticsPlugin.m index 583f1e0f5cff..da3617c7c382 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/FLTFirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/FLTFirebaseCrashlyticsPlugin.m @@ -7,12 +7,8 @@ #import "include/ExceptionModel_Platform.h" @import FirebaseCrashlytics; - -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; NSString *const kFLTFirebaseCrashlyticsChannelName = @"plugins.flutter.io/firebase_crashlytics"; NSString *const kFLTFirebaseCrashlyticsTestChannelName = @@ -75,7 +71,8 @@ + (void)registerWithRegistrar:(NSObject *)registrar { } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutterResult { - FLTFirebaseMethodCallErrorBlock errorBlock = + void (^errorBlock)(NSString *_Nullable, NSString *_Nullable, NSDictionary *_Nullable, + NSError *_Nullable) = ^(NSString *_Nullable code, NSString *_Nullable message, NSDictionary *_Nullable details, NSError *_Nullable error) { // `result.error` is not called in this plugin so this block does nothing. @@ -239,12 +236,12 @@ - (FIRStackFrame *)generateFrame:(NSDictionary *)errorElement { #pragma mark - FLTFirebasePlugin -- (void)didReinitializeFirebaseCore:(void (^)(void))completion { +- (void)didReinitializeFirebaseCoreWithCompletion:(void (^)(void))completion { // Not required for this plugin, nothing to cleanup between reloads. completion(); } -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *)firebase_app { +- (NSDictionary *_Nonnull)pluginConstantsFor:(FIRApp *)firebase_app { return @{ @"isCrashlyticsCollectionEnabled" : @([FIRCrashlytics crashlytics].isCrashlyticsCollectionEnabled) diff --git a/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/include/FLTFirebaseCrashlyticsPlugin.h b/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/include/FLTFirebaseCrashlyticsPlugin.h index 80bfe4d89435..483d9eb7ed50 100644 --- a/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/include/FLTFirebaseCrashlyticsPlugin.h +++ b/packages/firebase_crashlytics/firebase_crashlytics/ios/firebase_crashlytics/Sources/firebase_crashlytics/include/FLTFirebaseCrashlyticsPlugin.h @@ -10,12 +10,7 @@ #endif #import +@import firebase_core; -#if __has_include() -#import -#else -#import -#endif - -@interface FLTFirebaseCrashlyticsPlugin : FLTFirebasePlugin +@interface FLTFirebaseCrashlyticsPlugin : NSObject @end diff --git a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseObserveStreamHandler.m b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseObserveStreamHandler.m index 2d246c7c089b..15a2df835a00 100644 --- a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseObserveStreamHandler.m +++ b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseObserveStreamHandler.m @@ -3,11 +3,8 @@ // found in the LICENSE file. @import FirebaseDatabase; -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; #import "FLTFirebaseDatabaseObserveStreamHandler.h" #import "FLTFirebaseDatabaseUtils.h" @@ -54,10 +51,10 @@ - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments @"message" : message, }; dispatch_async(dispatch_get_main_queue(), ^{ - events([FLTFirebasePlugin createFlutterErrorFromCode:code - message:message - optionalDetails:details - andOptionalNSError:error]); + events([FLTFirebasePluginHelper createFlutterErrorWithCode:code + message:message + optionalDetails:details + andOptionalError:error]); }); }; diff --git a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabasePlugin.m b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabasePlugin.m index bd42988225b8..30a293bfaaa7 100644 --- a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabasePlugin.m +++ b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabasePlugin.m @@ -2,14 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; -#import "FLTFirebaseDatabaseObserveStreamHandler.h" #import "FLTFirebaseDatabasePlugin.h" +#import "FLTFirebaseDatabaseObserveStreamHandler.h" #import "FLTFirebaseDatabaseUtils.h" NSString *const kFLTFirebaseDatabaseChannelName = @"plugins.flutter.io/firebase_database"; @@ -69,7 +66,8 @@ - (void)detachFromEngineForRegistrar:(NSObject *)registr } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutterResult { - FLTFirebaseMethodCallErrorBlock errorBlock = + void (^errorBlock)(NSString *_Nullable, NSString *_Nullable, NSDictionary *_Nullable, + NSError *_Nullable) = ^(NSString *_Nullable code, NSString *_Nullable message, NSDictionary *_Nullable details, NSError *_Nullable error) { if (code == nil) { @@ -84,10 +82,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutter if ([@"unknown" isEqualToString:code]) { NSLog(@"FLTFirebaseDatabase: An error occurred while calling method %@", call.method); } - flutterResult([FLTFirebasePlugin createFlutterErrorFromCode:code - message:message - optionalDetails:details - andOptionalNSError:error]); + flutterResult([FLTFirebasePluginHelper createFlutterErrorWithCode:code + message:message + optionalDetails:details + andOptionalError:error]); }; FLTFirebaseMethodCallResult *methodCallResult = @@ -130,11 +128,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutter #pragma mark - FLTFirebasePlugin -- (void)didReinitializeFirebaseCore:(void (^)(void))completion { +- (void)didReinitializeFirebaseCoreWithCompletion:(void (^)(void))completion { [self cleanupWithCompletion:completion]; } -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *)firebase_app { +- (NSDictionary *_Nonnull)pluginConstantsFor:(FIRApp *)firebase_app { return @{}; } diff --git a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseUtils.m b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseUtils.m index 21c392f02693..4c3e2aa344e7 100644 --- a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseUtils.m +++ b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/FLTFirebaseDatabaseUtils.m @@ -3,11 +3,8 @@ // found in the LICENSE file. #import "FLTFirebaseDatabaseUtils.h" -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; @implementation FLTFirebaseDatabaseUtils static __strong NSMutableDictionary *cachedDatabaseInstances = nil; @@ -34,7 +31,7 @@ + (FIRDatabase *)databaseFromArguments:(id)arguments { return cachedInstance; } - FIRApp *app = [FLTFirebasePlugin firebaseAppNamed:appName]; + FIRApp *app = [FIRApp appNamed:appName]; FIRDatabase *database; if (databaseURL.length == 0) { diff --git a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/include/FLTFirebaseDatabasePlugin.h b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/include/FLTFirebaseDatabasePlugin.h index 591532786ac6..09691ab96492 100644 --- a/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/include/FLTFirebaseDatabasePlugin.h +++ b/packages/firebase_database/firebase_database/ios/firebase_database/Sources/firebase_database/include/FLTFirebaseDatabasePlugin.h @@ -13,11 +13,7 @@ #endif #import -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; -@interface FLTFirebaseDatabasePlugin : FLTFirebasePlugin +@interface FLTFirebaseDatabasePlugin : NSObject @end diff --git a/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/FirebaseInAppMessagingPlugin.m b/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/FirebaseInAppMessagingPlugin.m index 64519a1ca9db..de53d4bdfbea 100644 --- a/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/FirebaseInAppMessagingPlugin.m +++ b/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/FirebaseInAppMessagingPlugin.m @@ -5,12 +5,7 @@ #import "FirebaseInAppMessagingPlugin.h" @import FirebaseInAppMessaging; - -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; NSString *const kFLTFirebaseInAppMessagingChannelName = @"plugins.flutter.io/firebase_in_app_messaging"; diff --git a/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/include/FirebaseInAppMessagingPlugin.h b/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/include/FirebaseInAppMessagingPlugin.h index 37ba0b5579d2..96e59e05b521 100644 --- a/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/include/FirebaseInAppMessagingPlugin.h +++ b/packages/firebase_in_app_messaging/firebase_in_app_messaging/ios/firebase_in_app_messaging/Sources/firebase_in_app_messaging/include/FirebaseInAppMessagingPlugin.h @@ -6,12 +6,7 @@ #import #import +@import firebase_core; -#if __has_include() -#import -#else -#import -#endif - -@interface FirebaseInAppMessagingPlugin : FLTFirebasePlugin +@interface FirebaseInAppMessagingPlugin : NSObject @end diff --git a/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m b/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m index d62ffdc0dc2f..8efa03a01a15 100644 --- a/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m +++ b/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/FLTFirebaseMessagingPlugin.m @@ -4,11 +4,8 @@ #import #import -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; +@import FirebaseCore; #import #import "FLTFirebaseMessagingPlugin.h" @@ -93,9 +90,10 @@ + (void)registerWithRegistrar:(NSObject *)registrar { } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutterResult { - FLTFirebaseMethodCallErrorBlock errorBlock = ^( - NSString *_Nullable code, NSString *_Nullable message, NSDictionary *_Nullable details, - NSError *_Nullable error) { + void (^errorBlock)(NSString *_Nullable, NSString *_Nullable, NSDictionary *_Nullable, + NSError *_Nullable) = ^(NSString *_Nullable code, NSString *_Nullable message, + NSDictionary *_Nullable details, + NSError *_Nullable error) { if (code == nil) { NSDictionary *errorDetails = [self NSDictionaryForNSError:error]; code = errorDetails[kMessagingArgumentCode]; @@ -113,10 +111,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)flutter call.method, [error userInfo]); } - flutterResult([FLTFirebasePlugin createFlutterErrorFromCode:code - message:message - optionalDetails:details - andOptionalNSError:error]); + flutterResult([FLTFirebasePluginHelper createFlutterErrorWithCode:code + message:message + optionalDetails:details + andOptionalError:error]); }; FLTFirebaseMethodCallResult *methodCallResult = @@ -291,7 +289,7 @@ - (void)application_onDidFinishLaunchingNotification:(nonnull NSNotification *)n } if (shouldReplaceDelegate) { - __strong FLTFirebasePlugin *strongSelf = self; + __strong FLTFirebaseMessagingPlugin *strongSelf = self; notificationCenter.delegate = strongSelf; } } @@ -686,11 +684,11 @@ - (void)messagingDeleteToken:(id)arguments #pragma mark - FLTFirebasePlugin -- (void)didReinitializeFirebaseCore:(void (^)(void))completion { +- (void)didReinitializeFirebaseCoreWithCompletion:(void (^)(void))completion { completion(); } -- (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *)firebase_app { +- (NSDictionary *_Nonnull)pluginConstantsFor:(FIRApp *)firebase_app { return @{ @"AUTO_INIT_ENABLED" : @([FIRMessaging messaging].isAutoInitEnabled), }; diff --git a/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/include/FLTFirebaseMessagingPlugin.h b/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/include/FLTFirebaseMessagingPlugin.h index 2f32bac24d5d..698580ee1ba5 100644 --- a/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/include/FLTFirebaseMessagingPlugin.h +++ b/packages/firebase_messaging/firebase_messaging/ios/firebase_messaging/Sources/firebase_messaging/include/FLTFirebaseMessagingPlugin.h @@ -14,11 +14,7 @@ #import #import -#if __has_include() -#import -#else -#import -#endif +@import firebase_core; #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 #define __FF_NOTIFICATIONS_SUPPORTED_PLATFORM @@ -31,28 +27,26 @@ #if TARGET_OS_OSX #ifdef __FF_NOTIFICATIONS_SUPPORTED_PLATFORM -@interface FLTFirebaseMessagingPlugin : FLTFirebasePlugin +@interface FLTFirebaseMessagingPlugin : NSObject #else -@interface FLTFirebaseMessagingPlugin : FLTFirebasePlugin +@interface FLTFirebaseMessagingPlugin + : NSObject #endif #else #ifdef __FF_NOTIFICATIONS_SUPPORTED_PLATFORM API_AVAILABLE(ios(10.0)) -@interface FLTFirebaseMessagingPlugin : FLTFirebasePlugin +@interface FLTFirebaseMessagingPlugin : NSObject #else @interface FLTFirebaseMessagingPlugin - : FLTFirebasePlugin + : NSObject #endif #endif @end diff --git a/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/ios/firebase_ml_model_downloader/Sources/firebase_ml_model_downloader/FirebaseModelDownloaderPlugin.swift b/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/ios/firebase_ml_model_downloader/Sources/firebase_ml_model_downloader/FirebaseModelDownloaderPlugin.swift index 3d512ac1457a..b4354a0a8fef 100644 --- a/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/ios/firebase_ml_model_downloader/Sources/firebase_ml_model_downloader/FirebaseModelDownloaderPlugin.swift +++ b/packages/firebase_ml_model_downloader/firebase_ml_model_downloader/ios/firebase_ml_model_downloader/Sources/firebase_ml_model_downloader/FirebaseModelDownloaderPlugin.swift @@ -19,7 +19,7 @@ import FirebaseMLModelDownloader let kFLTFirebaseModelDownloaderChannelName = "plugins.flutter.io/firebase_ml_model_downloader" -public class FirebaseModelDownloaderPlugin: NSObject, FLTFirebasePluginProtocol, FlutterPlugin { +public class FirebaseModelDownloaderPlugin: NSObject, FLTFirebasePlugin, FlutterPlugin { public static func register(with registrar: FlutterPluginRegistrar) { let binaryMessenger: FlutterBinaryMessenger @@ -34,30 +34,30 @@ public class FirebaseModelDownloaderPlugin: NSObject, FLTFirebasePluginProtocol, binaryMessenger: binaryMessenger ) let instance = FirebaseModelDownloaderPlugin() - FLTFirebasePluginRegistry.sharedInstance().register(instance) + FLTFirebasePluginRegistry.sharedInstance().registerFirebasePlugin(instance) registrar.addMethodCallDelegate(instance, channel: channel) #if os(iOS) registrar.publish(instance) #endif } - public func firebaseLibraryVersion() -> String { - versionNumber - } - - public func didReinitializeFirebaseCore(_ completion: @escaping () -> Void) { + public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { completion() } - public func pluginConstants(for firebaseApp: FirebaseApp) -> [AnyHashable: Any] { + public func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] { [:] } - @objc public func firebaseLibraryName() -> String { + public var firebaseLibraryName: String { "flutter-fire-ml-downloader" } - @objc public func flutterChannelName() -> String { + public var firebaseLibraryVersion: String { + versionNumber + } + + public var flutterChannelName: String { "plugins.flutter.io/firebase_ml_model_downloader" } @@ -94,12 +94,12 @@ public class FirebaseModelDownloaderPlugin: NSObject, FLTFirebasePluginProtocol, NSLog("FLTFirebaseModelDownloader: An error occurred while calling method %@", call.method) } - result(FLTFirebasePlugin.createFlutterError(fromCode: errorDetails["code"] as! String, - message: errorDetails["message"] as! String, - optionalDetails: errorDetails[ - "additionalData" - ] as? [AnyHashable: Any], - andOptionalNSError: nil)) + result(FLTFirebasePluginHelper.createFlutterError(code: errorDetails["code"] as! String, + message: errorDetails["message"] as! String, + optionalDetails: errorDetails[ + "additionalData" + ] as? [String: Any], + andOptionalError: nil as Error?)) } let result = FLTFirebaseMethodCallResult.create(success: result, andErrorBlock: errorBlock) @@ -189,7 +189,8 @@ public class FirebaseModelDownloaderPlugin: NSObject, FLTFirebasePluginProtocol, } func modelDownloaderFromArguments(arguments: [String: Any]) -> ModelDownloader? { - let app: FirebaseApp = FLTFirebasePlugin.firebaseAppNamed(arguments["appName"] as! String)! + let app: FirebaseApp = FLTFirebasePluginHelper + .firebaseApp(named: arguments["appName"] as! String)! return ModelDownloader.modelDownloader(app: app) } } diff --git a/packages/firebase_performance/firebase_performance/android/src/main/kotlin/io/flutter/plugins/firebase/performance/FlutterFirebasePerformancePlugin.kt b/packages/firebase_performance/firebase_performance/android/src/main/kotlin/io/flutter/plugins/firebase/performance/FlutterFirebasePerformancePlugin.kt index dfc913d0700e..fc26a4d11dde 100644 --- a/packages/firebase_performance/firebase_performance/android/src/main/kotlin/io/flutter/plugins/firebase/performance/FlutterFirebasePerformancePlugin.kt +++ b/packages/firebase_performance/firebase_performance/android/src/main/kotlin/io/flutter/plugins/firebase/performance/FlutterFirebasePerformancePlugin.kt @@ -170,8 +170,8 @@ class FlutterFirebasePerformancePlugin return taskCompletionSource.task } - override fun didReinitializeFirebaseCore(): Task { - val taskCompletionSource = TaskCompletionSource() + override fun didReinitializeFirebaseCore(): Task { + val taskCompletionSource = TaskCompletionSource() FlutterFirebasePlugin.cachedThreadPool.execute { try { diff --git a/packages/firebase_performance/firebase_performance/ios/firebase_performance/Package.swift b/packages/firebase_performance/firebase_performance/ios/firebase_performance/Package.swift index b47de11bb2ec..32a63487c11a 100644 --- a/packages/firebase_performance/firebase_performance/ios/firebase_performance/Package.swift +++ b/packages/firebase_performance/firebase_performance/ios/firebase_performance/Package.swift @@ -109,11 +109,6 @@ let package = Package( ], resources: [ .process("Resources"), - ], - cSettings: [ - .headerSearchPath("include"), - .define("LIBRARY_VERSION", to: "\"\(library_version)\""), - .define("LIBRARY_NAME", to: "\"flutter-fire-perf\""), ] ), ] diff --git a/packages/firebase_performance/firebase_performance/ios/firebase_performance/Sources/firebase_performance/FirebasePerformancePlugin.swift b/packages/firebase_performance/firebase_performance/ios/firebase_performance/Sources/firebase_performance/FirebasePerformancePlugin.swift index 6d0ac5c39979..1270f3fed3c7 100644 --- a/packages/firebase_performance/firebase_performance/ios/firebase_performance/Sources/firebase_performance/FirebasePerformancePlugin.swift +++ b/packages/firebase_performance/firebase_performance/ios/firebase_performance/Sources/firebase_performance/FirebasePerformancePlugin.swift @@ -13,31 +13,32 @@ #else import firebase_core_shared #endif +import FirebaseCore import FirebasePerformance let FirebasePerformanceChannelName = "plugins.flutter.io/firebase_performance" extension FlutterError: Error {} -public class FirebasePerformancePlugin: NSObject, FlutterPlugin, FLTFirebasePluginProtocol, +public class FirebasePerformancePlugin: NSObject, FlutterPlugin, FLTFirebasePlugin, FirebasePerformanceHostApi { - public func didReinitializeFirebaseCore(_ completion: @escaping () -> Void) { + public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { completion() } - public func pluginConstants(for firebaseApp: FirebaseApp) -> [AnyHashable: Any] { + public func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] { [:] } - public func firebaseLibraryName() -> String { + public var firebaseLibraryName: String { "flutter-fire-perf" } - public func firebaseLibraryVersion() -> String { + public var firebaseLibraryVersion: String { versionNumber } - public func flutterChannelName() -> String { + public var flutterChannelName: String { FirebasePerformanceChannelName } diff --git a/packages/firebase_remote_config/firebase_remote_config/android/src/main/kotlin/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.kt b/packages/firebase_remote_config/firebase_remote_config/android/src/main/kotlin/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.kt index 2700a45258cb..598f7d0d718a 100644 --- a/packages/firebase_remote_config/firebase_remote_config/android/src/main/kotlin/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.kt +++ b/packages/firebase_remote_config/firebase_remote_config/android/src/main/kotlin/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.kt @@ -79,8 +79,8 @@ class FirebaseRemoteConfigPlugin return configProperties } - override fun didReinitializeFirebaseCore(): Task { - val taskCompletionSource = TaskCompletionSource() + override fun didReinitializeFirebaseCore(): Task { + val taskCompletionSource = TaskCompletionSource() FlutterFirebasePlugin.cachedThreadPool.execute { try { diff --git a/packages/firebase_remote_config/firebase_remote_config/ios/firebase_remote_config/Sources/firebase_remote_config/FirebaseRemoteConfigPlugin.swift b/packages/firebase_remote_config/firebase_remote_config/ios/firebase_remote_config/Sources/firebase_remote_config/FirebaseRemoteConfigPlugin.swift index efc37811db97..5418b474d980 100644 --- a/packages/firebase_remote_config/firebase_remote_config/ios/firebase_remote_config/Sources/firebase_remote_config/FirebaseRemoteConfigPlugin.swift +++ b/packages/firebase_remote_config/firebase_remote_config/ios/firebase_remote_config/Sources/firebase_remote_config/FirebaseRemoteConfigPlugin.swift @@ -13,6 +13,7 @@ #else import firebase_core_shared #endif +import FirebaseCore import FirebaseRemoteConfig let kFirebaseRemoteConfigChannelName = "plugins.flutter.io/firebase_remote_config" @@ -21,13 +22,13 @@ let kFirebaseRemoteConfigUpdatedChannelName = "plugins.flutter.io/firebase_remot extension FlutterError: Error {} public class FirebaseRemoteConfigPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, - FLTFirebasePluginProtocol, FirebaseRemoteConfigHostApi { + FLTFirebasePlugin, FirebaseRemoteConfigHostApi { private var listenersMap: [String: ConfigUpdateListenerRegistration] = [:] private var fetchAndActivateRetry = false static let shared: FirebaseRemoteConfigPlugin = { let instance = FirebaseRemoteConfigPlugin() - FLTFirebasePluginRegistry.sharedInstance().register(instance) + FLTFirebasePluginRegistry.sharedInstance().registerFirebasePlugin(instance) instance.fetchAndActivateRetry = false return instance }() @@ -53,17 +54,17 @@ public class FirebaseRemoteConfigPlugin: NSObject, FlutterPlugin, FlutterStreamH if FirebaseApp.responds(to: NSSelectorFromString("registerLibrary:withVersion:")) { FirebaseApp.perform( NSSelectorFromString("registerLibrary:withVersion:"), - with: instance.firebaseLibraryName(), - with: instance.firebaseLibraryVersion() + with: instance.firebaseLibraryName, + with: instance.firebaseLibraryVersion ) } } - public func didReinitializeFirebaseCore(_ completion: @escaping () -> Void) { + public func didReinitializeFirebaseCore(completion: @escaping () -> Void) { completion() } - public func pluginConstants(for firebaseApp: FirebaseApp) -> [AnyHashable: Any] { + public func pluginConstants(for firebaseApp: FirebaseApp) -> [String: Any] { let firebaseRemoteConfig = RemoteConfig.remoteConfig(app: firebaseApp) let configProperties = configProperties(for: firebaseRemoteConfig) var configValues: [String: Any] = configProperties @@ -173,15 +174,15 @@ public class FirebaseRemoteConfigPlugin: NSObject, FlutterPlugin, FlutterStreamH completion(.success(configProperties(for: config))) } - public func firebaseLibraryName() -> String { + public var firebaseLibraryName: String { "flutter-fire-rc" } - public func firebaseLibraryVersion() -> String { + public var firebaseLibraryVersion: String { versionNumber } - public func flutterChannelName() -> String { + public var flutterChannelName: String { kFirebaseRemoteConfigChannelName } @@ -213,7 +214,7 @@ public class FirebaseRemoteConfigPlugin: NSObject, FlutterPlugin, FlutterStreamH } private func getRemoteConfig(from appName: String) -> RemoteConfig { - let app = FLTFirebasePlugin.firebaseAppNamed(appName) + let app = FLTFirebasePluginHelper.firebaseApp(named: appName) return RemoteConfig.remoteConfig(app: app!) } diff --git a/packages/firebase_storage/firebase_storage/android/src/main/kotlin/io/flutter/plugins/firebase/storage/FlutterFirebaseStoragePlugin.kt b/packages/firebase_storage/firebase_storage/android/src/main/kotlin/io/flutter/plugins/firebase/storage/FlutterFirebaseStoragePlugin.kt index 7453d5040713..8f4b1e7fcee9 100644 --- a/packages/firebase_storage/firebase_storage/android/src/main/kotlin/io/flutter/plugins/firebase/storage/FlutterFirebaseStoragePlugin.kt +++ b/packages/firebase_storage/firebase_storage/android/src/main/kotlin/io/flutter/plugins/firebase/storage/FlutterFirebaseStoragePlugin.kt @@ -22,7 +22,6 @@ import io.flutter.plugin.common.EventChannel import io.flutter.plugin.common.EventChannel.StreamHandler import io.flutter.plugin.common.MethodChannel import io.flutter.plugins.firebase.core.FlutterFirebasePlugin -import io.flutter.plugins.firebase.core.FlutterFirebasePlugin.cachedThreadPool import io.flutter.plugins.firebase.core.FlutterFirebasePluginRegistry import java.io.File import java.util.Locale @@ -443,18 +442,18 @@ class FlutterFirebaseStoragePlugin : FlutterFirebasePlugin, FlutterPlugin, Fireb callback(Result.success(Unit)) } - override fun getPluginConstantsForFirebaseApp(firebaseApp: FirebaseApp?): Task> { - val taskCompletionSource = TaskCompletionSource>() - cachedThreadPool.execute { + override fun getPluginConstantsForFirebaseApp(firebaseApp: FirebaseApp): Task> { + val taskCompletionSource = TaskCompletionSource>() + FlutterFirebasePlugin.cachedThreadPool.execute { val obj = HashMap() taskCompletionSource.setResult(obj) } return taskCompletionSource.task } - override fun didReinitializeFirebaseCore(): Task { - val taskCompletionSource = TaskCompletionSource() - cachedThreadPool.execute { + override fun didReinitializeFirebaseCore(): Task { + val taskCompletionSource = TaskCompletionSource() + FlutterFirebasePlugin.cachedThreadPool.execute { FlutterFirebaseStorageTask.cancelInProgressTasks() taskCompletionSource.setResult(null) removeEventListeners() diff --git a/packages/firebase_storage/firebase_storage/ios/firebase_storage.podspec b/packages/firebase_storage/firebase_storage/ios/firebase_storage.podspec index 7a475510a123..e5d55cd7b69a 100755 --- a/packages/firebase_storage/firebase_storage/ios/firebase_storage.podspec +++ b/packages/firebase_storage/firebase_storage/ios/firebase_storage.podspec @@ -25,8 +25,7 @@ Pod::Spec.new do |s| s.authors = 'The Chromium Authors' s.source = { :path => '.' } - s.source_files = 'firebase_storage/Sources/firebase_storage/**/*.{h,m,swift}' - s.public_header_files = 'firebase_storage/Sources/firebase_storage/include/*.h' + s.source_files = 'firebase_storage/Sources/firebase_storage/**/*.swift' s.swift_version = '5.0' diff --git a/packages/firebase_storage/firebase_storage/ios/firebase_storage/Package.swift b/packages/firebase_storage/firebase_storage/ios/firebase_storage/Package.swift index 52214ea17003..53f0cfb1bbd1 100644 --- a/packages/firebase_storage/firebase_storage/ios/firebase_storage/Package.swift +++ b/packages/firebase_storage/firebase_storage/ios/firebase_storage/Package.swift @@ -104,11 +104,6 @@ let package = Package( ], resources: [ .process("Resources"), - ], - cSettings: [ - .headerSearchPath("include"), - .define("LIBRARY_VERSION", to: "\"\(library_version)\""), - .define("LIBRARY_NAME", to: "\"flutter-fire-gcs\""), ] ), ] diff --git a/packages/firebase_storage/firebase_storage/ios/firebase_storage/Sources/firebase_storage/FLTFirebaseStoragePlugin.swift b/packages/firebase_storage/firebase_storage/ios/firebase_storage/Sources/firebase_storage/FLTFirebaseStoragePlugin.swift index 2696d2c9f94d..e60d54eea250 100644 --- a/packages/firebase_storage/firebase_storage/ios/firebase_storage/Sources/firebase_storage/FLTFirebaseStoragePlugin.swift +++ b/packages/firebase_storage/firebase_storage/ios/firebase_storage/Sources/firebase_storage/FLTFirebaseStoragePlugin.swift @@ -55,7 +55,7 @@ public final class FLTFirebaseStoragePlugin: NSObject, FlutterPlugin, FirebaseSt private func storage(app: PigeonStorageFirebaseApp) -> Storage { let base = "gs://" + app.bucket - let firApp = FLTFirebasePlugin.firebaseAppNamed(app.appName)! + let firApp = FLTFirebasePluginHelper.firebaseApp(named: app.appName)! return Storage.storage(app: firApp, url: base) } @@ -332,7 +332,7 @@ public final class FLTFirebaseStoragePlugin: NSObject, FlutterPlugin, FirebaseSt let uuid = UUID().uuidString let channelName = "plugins.flutter.io/firebase_storage/taskEvent/\(uuid)" let channel = FlutterEventChannel(name: channelName, binaryMessenger: messenger!) - let storageInstance = Storage.storage(app: FLTFirebasePlugin.firebaseAppNamed(appName)!) + let storageInstance = Storage.storage(app: FLTFirebasePluginHelper.firebaseApp(named: appName)!) channel.setStreamHandler(TaskStateChannelStreamHandler( task: task, storage: storageInstance, diff --git a/packages/firebase_storage/firebase_storage/macos/firebase_storage.podspec b/packages/firebase_storage/firebase_storage/macos/firebase_storage.podspec index 12c7a116a466..f2afd459132f 100755 --- a/packages/firebase_storage/firebase_storage/macos/firebase_storage.podspec +++ b/packages/firebase_storage/firebase_storage/macos/firebase_storage.podspec @@ -43,8 +43,7 @@ Pod::Spec.new do |s| s.authors = 'The Chromium Authors' s.source = { :path => '.' } - s.source_files = 'firebase_storage/Sources/firebase_storage/**/*.{h,m,swift}' - s.public_header_files = 'firebase_storage/Sources/firebase_storage/include/*.h' + s.source_files = 'firebase_storage/Sources/firebase_storage/**/*.swift' s.platform = :osx, '10.13' diff --git a/packages/firebase_storage/firebase_storage/macos/firebase_storage/Package.swift b/packages/firebase_storage/firebase_storage/macos/firebase_storage/Package.swift index 2362a8817283..55f1a2ce7f48 100644 --- a/packages/firebase_storage/firebase_storage/macos/firebase_storage/Package.swift +++ b/packages/firebase_storage/firebase_storage/macos/firebase_storage/Package.swift @@ -106,11 +106,6 @@ let package = Package( ], resources: [ .process("Resources"), - ], - cSettings: [ - .headerSearchPath("include"), - .define("LIBRARY_VERSION", to: "\"\(library_version)\""), - .define("LIBRARY_NAME", to: "\"flutter-fire-gcs\""), ] ), ]