I have struggled a lot to how to load resource in cocoapods resource_bundle.
The following is what i put in the .podspecs
file.
s.sourc
I don't think any of the other answers have described the relationship to the Podspec. The bundle URL uses the name of the pod and then .bundle
to find the resource bundle. This approach works with asset catalogs for accessing pod images both inside and outside of the pod.
Podspec
Pod::Spec.new do |s|
s.name = 'PodName'
s.resource_bundles = {
'ResourceBundleName' => ['path/to/resources/*/**']
}
end
Objective-C
// grab bundle using `Class` in pod source (`self`, in this case)
NSBundle *bundle = [NSBundle bundleForClass:self.classForCoder];
NSURL *bundleURL = [[bundle resourceURL] URLByAppendingPathComponent:@"PodName.bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithURL:bundleURL];
UIImage *podImage = [UIImage imageNamed:@"image_name" inBundle:resourceBundle compatibleWithTraitCollection:nil];
Swift
See this answer.