Problem
Simple ODR-enabled app built with a Xcode Server Bot does not have resources accessible to it even though conditionallyBeginAccessingResourcesWithCompletionHandler and beginAccessingResourcesWithCompletionHandler indicate success. In fact, conditionallyBeginAccessingResourcesWithCompletionHandler calls back with a true value for resourcesAvailable even if an invalid tag is specified!
Platform: Mac OS X El Capitan GM, Xcode 7 GM, Xcode Server 5 Beta
Steps:
1. Create a new Project and use the Single View Application template for Swift
2. Make sure Enable On Demand Resources is Yes in Build Settings for app target
3. Add one JPG named, Image.jpg, to the project and give it the tag, TheODRTag
4. Change the contents of ViewController.swift to the following:
private var request: NSBundleResourceRequest!
override func viewDidLoad() {
super.viewDidLoad()
request = NSBundleResourceRequest(tags: Set<String>(["TheODRTag"]))
request.conditionallyBeginAccessingResourcesWithCompletionHandler { [unowned self] resourcesAvailable in
if resourcesAvailable {
self.loadImage()
return
}
self.request.beginAccessingResourcesWithCompletionHandler { error in
if error == nil {
self.loadImage()
}
}
}
}
private func loadImage() {
dispatch_async(dispatch_get_main_queue()) { [unowned self] in
let imageView = UIImageView(frame: CGRectZero)
imageView.contentMode = .ScaleAspectFill
imageView.image = UIImage(named: "Image.jpg")
imageView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(imageView)
self.view.addConstraint(imageView.topAnchor.constraintEqualToAnchor(self.view.topAnchor))
self.view.addConstraint(imageView.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor))
self.view.addConstraint(imageView.trailingAnchor.constraintEqualToAnchor(self.view.trailingAnchor))
self.view.addConstraint(imageView.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor))
}
}
5. Run on device from Xcode, note the image is loaded
6. Create a Bot on Xcode Server using the default options and no triggers
7. Run the bot and note that it succeeds after "uploading on demand resources"
8. Install the app on-device from Xcode Server's Web interface
9. Run the app, note the image is not loaded. Adding debug messages and/or alerts shows that conditionallyBeginAccessingResourcesWithCompletionHandler erroneously indicates the resources are available, even on the first run.
What did I miss?
Thanks!