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
Asked
Active
Viewed 3,235 times
2 Answers
5
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.
}
}];
}
}];

Vlad Papko
- 13,184
- 4
- 41
- 57
4
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.

Roland Keesom
- 8,180
- 5
- 45
- 52
-
hello roland i just used in my demo for localization like this but it downloads all tags at once can you help me out – Abhilash Jul 30 '15 at 16:05
-
You need to edit the tags array and only download the ones you need at that time. – Roland Keesom Jul 31 '15 at 11:30