Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing and downloading on demand resources iOS9

I am trying to implement new iOS9 feature app thinning, I understood how tag an image and enable on demand resource in Xcode 7 but I don't understand how to implement NSBundleResourceRequest in my app, can someone help me, that would greatly appreciated

like image 541
Abhilash Avatar asked Jul 28 '15 22:07

Abhilash


People also ask

What are on demand resources?

On-demand resources are app contents that are hosted on the App Store and are separate from the related app bundle that you download. They enable smaller app bundles, faster downloads, and richer app content. The app requests sets of on-demand resources, and the operating system manages downloading and storage.

What is app slicing?

App Thinning chapter of App distribution guide says the following: "Slicing is the process of creating and delivering variants of the app bundle for different target devices. A variant contains only the executable architecture and resources that are needed for the target device."


2 Answers

Most of information is available in Apple documentation.

Basically you need make this:

NSSet *tagsSet = [NSSet setWithObjects:@"resourceTag1", @"resourceTag2", nil];
NSBundleResourceRequest *request = [[NSBundleResourceRequest alloc] initWithTags:tagsSet];
[request conditionallyBeginAccessingResourcesWithCompletionHandler:^(BOOL resourcesAvailable) {
    if (resourcesAvailable) {
        // Start using resources.
    } else {
        [request beginAccessingResourcesWithCompletionHandler:^(NSError * _Nullable error) {
            if (error == nil) {
                // Start using resources.
            }
        }];
    }
}];
like image 119
Vlad Papko Avatar answered Sep 27 '22 18:09

Vlad Papko


First, check if the resources are available. Else download them.

Here is the swift code I use

let tags = NSSet(array: ["tag1","tag2"])
let resourceRequest = NSBundleResourceRequest(tags: tags as! Set<String>)
resourceRequest.conditionallyBeginAccessingResourcesWithCompletionHandler {(resourcesAvailable: Bool) -> Void in
    if resourcesAvailable {
        // Do something with the resources
    } else {
        resourceRequest.beginAccessingResourcesWithCompletionHandler {(err: NSError?) -> Void in
            if let error = err {
                print("Error: \(error)")
            } else {
                // Do something with the resources
            }
        }
    }
}

I also found this guide very helpful.

like image 20
Roland Keesom Avatar answered Sep 27 '22 16:09

Roland Keesom