NSBundleResourceRequest No Progress

When I try to observe the progress of a NSBundleResourceRequest, observeValue(forKeyPath: object: change: context:) is not called for the .new observing option. Here is the setup and code:


Setup:

Xcode 8.3.1

Deployment Target iOS 10.3

Device: iPad 4

Resource tags (368 KB) are located located in Download Only On Demand and consist of thumbnails displayed in a UICollectionView.

Images are correctly displayed in the collection view.

Code:

final class MyCollectionVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

var myCollectionVCResourceRequest: NSBundleResourceRequest!

var myCollectionVCResourceRequestLoaded = false

static var myCollectionProgressObservingContext = UUID().uuidString


private let designThumbnailTags: Set<String> = ["Tag1", "Tag2", "Tag3"]


override func viewWillAppear(_ animated: Bool) {

super.viewWillAppear(animated)

loadOnDemandResources()

}


func loadOnDemandResources() {

myCollectionVCResourceRequest = NSBundleResourceRequest(tags: designThumbnailTags)

myCollectionVCResourceRequest.progress.addObserver(self, forKeyPath: "fractionCompleted", options: [.new, .initial], context: &MyCollectionVC.myCollectionProgressObservingContext)

myCollectionVCResourceRequest.beginAccessingResources(completionHandler: { (error) in

print("Complete: \(self.myCollectionVCResourceRequest.progress.fractionCompleted)") // Prints Complete: 0.0

self.myCollectionVCResourceRequest.progress.removeObserver(self, forKeyPath: "fractionCompleted", context: &MyCollectionVC.myCollectionProgressObservingContext)

OperationQueue.main.addOperation({

guard error == nil else { self.handleOnDemandResourceError(error! as NSError); return }


self.myCollectionVCResourceRequestLoaded = true

self.updateViewsForOnDemandResourceAvailability()

self.fetchDesignThumbnailsWithOnDemandResourceTags(self.myCollectionVCResourceRequest) // Correctly creates Core Data Instances

})

})

}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

if context == &MyCollectionVC.myCollectionProgressObservingContext {

OperationQueue.main.addOperation({

let progressObject = object as! Progress

self.progressView.progress = Float(progressObject.fractionCompleted)

print(Float(progressObject.fractionCompleted)) // Prints 0.0 as a result of including the .initial option

self.progressDetailLabel.text = progressObject.localizedDescription

})

}

else {

super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)

}

}

}

I too cannot get the fractionCompleted to be updated. Using the addObserver shown in https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/On_Demand_Resources_Guide/Managing.html#//apple_ref/doc/uid/TP40015083-CH4-SW1


The code is never called.


But even after the bundle is loaded, asking for the fractionComplete returns 0.


My bundles are loading nicely from my remote server but I get no feedback.


Any ideas?

thanks,

scott

I'm also struggeling with this since I build against iOS13 SDK. No progress or reliable download information. Also if I follow the myCollectionVCResourceRequest.Progress.fractionCompleted manually it stays 0 until it's at 1. This is in TestFlight and it used to work in TestFlight like in the App Store. Seems I have to release the app to find out if the App Store version does give progress. Don't want to go there obviously.

NSBundleResourceRequest No Progress
 
 
Q