diff --git a/FirebaseStorage.podspec b/FirebaseStorage.podspec index 05acbde7a48..45c4208c7ce 100644 --- a/FirebaseStorage.podspec +++ b/FirebaseStorage.podspec @@ -42,6 +42,7 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas s.dependency 'FirebaseCore', '~> 10.0' s.dependency 'FirebaseCoreExtension', '~> 10.0' s.dependency 'GTMSessionFetcher/Core', '>= 2.1', '< 4.0' + s.dependency 'GoogleUtilities/Environment', '~> 7.12' s.test_spec 'ObjCIntegration' do |objc_tests| objc_tests.scheme = { :code_coverage => true } diff --git a/FirebaseStorage/CHANGELOG.md b/FirebaseStorage/CHANGELOG.md index 745d374cfd7..ad18b9c19fe 100644 --- a/FirebaseStorage/CHANGELOG.md +++ b/FirebaseStorage/CHANGELOG.md @@ -1,3 +1,7 @@ +# Unreleased +- [fixed] `putFile` and `putFileAsync` now work in app extensions. A background session + configuration is not used when uploading from an app extension (#12579). + # 10.11.0 - [added] Add progress tracking capability for `putDataAsync`, `putFileAsync`, and `writeAsync`. (#10574) diff --git a/FirebaseStorage/Sources/AsyncAwait.swift b/FirebaseStorage/Sources/AsyncAwait.swift index 564a2378aaa..8fffded0e18 100644 --- a/FirebaseStorage/Sources/AsyncAwait.swift +++ b/FirebaseStorage/Sources/AsyncAwait.swift @@ -73,7 +73,6 @@ public extension StorageReference { } /// Asynchronously uploads a file to the currently specified StorageReference. - /// `putDataAsync` should be used instead of `putFileAsync` in Extensions. /// /// - Parameters: /// - url: A URL representing the system file path of the object to be uploaded. diff --git a/FirebaseStorage/Sources/StorageReference.swift b/FirebaseStorage/Sources/StorageReference.swift index 98eb595c733..d3d45d6e2df 100644 --- a/FirebaseStorage/Sources/StorageReference.swift +++ b/FirebaseStorage/Sources/StorageReference.swift @@ -136,7 +136,6 @@ import Foundation } /// Asynchronously uploads a file to the currently specified `StorageReference`. - /// `putData` should be used instead of `putFile` in Extensions. /// - Parameters: /// - fileURL: A URL representing the system file path of the object to be uploaded. /// - metadata: `StorageMetadata` containing additional information (MIME type, etc.) @@ -150,7 +149,6 @@ import Foundation /// Asynchronously uploads a file to the currently specified `StorageReference`, /// without additional metadata. - /// `putData` should be used instead of `putFile` in Extensions. /// @param fileURL A URL representing the system file path of the object to be uploaded. /// @return An instance of StorageUploadTask, which can be used to monitor or manage the upload. @objc(putFile:) @discardableResult open func __putFile(from fileURL: URL) -> StorageUploadTask { @@ -158,7 +156,6 @@ import Foundation } /// Asynchronously uploads a file to the currently specified `StorageReference`. - /// `putData` should be used instead of `putFile` in Extensions. /// - Parameters: /// - fileURL: A URL representing the system file path of the object to be uploaded. /// - metadata: `StorageMetadata` containing additional information (MIME type, etc.) diff --git a/FirebaseStorage/Sources/StorageUploadTask.swift b/FirebaseStorage/Sources/StorageUploadTask.swift index 759fd6b47c5..0d1e904661f 100644 --- a/FirebaseStorage/Sources/StorageUploadTask.swift +++ b/FirebaseStorage/Sources/StorageUploadTask.swift @@ -14,6 +14,12 @@ import Foundation +#if SWIFT_PACKAGE + @_implementationOnly import GoogleUtilities_Environment +#else + @_implementationOnly import GoogleUtilities +#endif // SWIFT_PACKAGE + #if COCOAPODS import GTMSessionFetcher #else @@ -87,6 +93,10 @@ import Foundation } else if let fileURL = self.fileURL { uploadFetcher.uploadFileURL = fileURL uploadFetcher.comment = "File UploadTask" + + if GULAppEnvironmentUtil.isAppExtension() { + uploadFetcher.useBackgroundSession = false + } } uploadFetcher.maxRetryInterval = self.reference.storage.maxUploadRetryInterval diff --git a/Package.swift b/Package.swift index fab9bd71a96..677f8ae90d5 100644 --- a/Package.swift +++ b/Package.swift @@ -1161,6 +1161,7 @@ let package = Package( "FirebaseCore", "FirebaseCoreExtension", .product(name: "GTMSessionFetcherCore", package: "gtm-session-fetcher"), + .product(name: "GULEnvironment", package: "GoogleUtilities"), ], path: "FirebaseStorage/Sources" ),