Skip to content
1 change: 1 addition & 0 deletions Sources/Jetpack/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<array>
<string>org.wordpress.bgtask.weeklyroundup</string>
<string>org.wordpress.bgtask.weeklyroundup.processing</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).mediaUpload</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
Expand Down
17 changes: 9 additions & 8 deletions Sources/WordPress/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<array>
<string>org.wordpress.bgtask.weeklyroundup</string>
<string>org.wordpress.bgtask.weeklyroundup.processing</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).mediaUpload</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
Expand Down Expand Up @@ -191,13 +192,13 @@
<key>UIPrerenderedIcon</key>
<true/>
</dict>
<key>Spectrum &apos;22</key>
<key>Spectrum '22</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>spectrum-&apos;22-icon-app-60x60</string>
<string>spectrum-&apos;22-icon-app-76x76</string>
<string>spectrum-&apos;22-icon-app-83.5x83.5</string>
<string>spectrum-'22-icon-app-60x60</string>
<string>spectrum-'22-icon-app-76x76</string>
<string>spectrum-'22-icon-app-83.5x83.5</string>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xcode made these changes. Xcode also made the original changes. Somehow, Xcode decides to revert changes that were made by itself...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of Xcode are you on?

</array>
<key>UIPrerenderedIcon</key>
<true/>
Expand Down Expand Up @@ -406,13 +407,13 @@
<key>UIPrerenderedIcon</key>
<true/>
</dict>
<key>Spectrum &apos;22</key>
<key>Spectrum '22</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>spectrum-&apos;22-icon-app-60x60</string>
<string>spectrum-&apos;22-icon-app-76x76</string>
<string>spectrum-&apos;22-icon-app-83.5x83.5</string>
<string>spectrum-'22-icon-app-60x60</string>
<string>spectrum-'22-icon-app-76x76</string>
<string>spectrum-'22-icon-app-83.5x83.5</string>
</array>
<key>UIPrerenderedIcon</key>
<true/>
Expand Down
10 changes: 7 additions & 3 deletions WordPress/Classes/Services/MediaCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class MediaCoordinator: NSObject {
/// - parameter origin: The location in the app where the upload was initiated (optional).
///
func addMedia(from asset: ExportableAsset, to blog: Blog, analyticsInfo: MediaAnalyticsInfo? = nil) {
addMedia(from: asset, blog: blog, post: nil, coordinator: mediaLibraryProgressCoordinator, analyticsInfo: analyticsInfo)
addMedia(from: asset, blog: blog, coordinator: mediaLibraryProgressCoordinator, analyticsInfo: analyticsInfo)
}

/// Adds the specified media asset to the specified post. The upload process
Expand Down Expand Up @@ -192,14 +192,14 @@ class MediaCoordinator: NSObject {
/// Create a `Media` instance and upload the asset to the Media Library.
///
/// - SeeAlso: `MediaImportService.createMedia(with:blog:post:receiveUpdate:thumbnailCallback:completion:)`
private func addMedia(from asset: ExportableAsset, blog: Blog, post: AbstractPost?, coordinator: MediaProgressCoordinator, analyticsInfo: MediaAnalyticsInfo? = nil) {
private func addMedia(from asset: ExportableAsset, blog: Blog, coordinator: MediaProgressCoordinator, analyticsInfo: MediaAnalyticsInfo? = nil) {
coordinator.track(numberOfItems: 1)
let service = MediaImportService(coreDataStack: coreDataStack)
let totalProgress = Progress.discreteProgress(totalUnitCount: MediaExportProgressUnits.done)
let creationProgress = service.createMedia(
with: asset,
blog: blog,
post: post,
post: nil,
receiveUpdate: { [weak self] media in
self?.processing(media)
coordinator.track(progress: totalProgress, of: media, withIdentifier: media.uploadID)
Expand Down Expand Up @@ -453,6 +453,10 @@ class MediaCoordinator: NSObject {
WPAppAnalytics.track(event, properties: properties, blog: media.blog)
}

func submitBackgroundUploadTask() {
mediaLibraryProgressCoordinator.submitBackgroundUploadTask()
}

// MARK: - Progress

/// - returns: The current progress for the specified media object.
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public class WordPressAppDelegate: UIResponder, UIApplicationDelegate {

public func applicationWillResignActive(_ application: UIApplication) {
DDLogInfo("\(self) \(#function)")
MediaCoordinator.shared.submitBackgroundUploadTask()
}

public func applicationDidBecomeActive(_ application: UIApplication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ public class MediaProgressCoordinator: NSObject {
mediaInProgress[mediaID] = progress
}

/// Utilize BGContinuedProcessingTask to show upload progress and extend the allowed background time for the upload.
/// Note: This function needs to be called before the app goes to the background.
func submitBackgroundUploadTask() {
guard let scheduler = mediaUploadBackgroundTaskScheduler() else { return }

for (mediaID, progress) in mediaInProgress {
guard let media = media(withIdentifier: mediaID) else {
continue
}
if media.remoteStatus == .pushing || media.remoteStatus == .processing {
scheduler.scheduleTask(for: TaggedManagedObjectID(media), progress: progress)
}
}
}

/// Finish one of the tasks.
///
/// Note: This method is used to advance the completed number of tasks, when the task doesn't have any relevant associated work/progress to be tracked.
Expand Down
Loading