I use methods about creating a universal binary framework for iOS development to distribute a library. I would also like to add files in the framework, and load them in the main program (an SSL certificate actually). This is related to this StackOverflow question, the main difference is that I want to include something else than a XIB.
If we read the thread related to the linked post, it seems it is not possible. However, the following blog article was mentioned; we can read:
"Static frameworks are not a full replacement for standard frameworks -- standard methods for accessing the framework resources, such as
+[NSBundle bundleForClass:]
will not return the expected bundle. The bundle path is determined by querying dyld for the library path corresponding to the symbol address -- In the case of static linking, this will return the path to the binary into which the static library was linked. Additionally,NSBundle/CFBundle
will examine the previous stack from for the return address, and use that return address to determine the calling code's dyld binary path. Given these restrictions, some work-arounds are possible, such as using-[NSBundle privateFrameworkPath]
to locate the path to the embedded framework."
I am a beginner in iOS development, and I struggle in using such a mechanism. Using the privateFrameworksPath
returns a path indeed, but I do not know what to do next to locate the file I want to load.
It is something like that:
NSBundle * bundle = [NSBundle bundleForClass:[self class]];
NSString * path = [bundle privateFrameworksPath]; // Works, return something like .../Frameworks
NSString * file = [path stringByAppendingPathComponent:@"MyFramework.framework/Versions/A/my-cert.der"];
NSData * trustedCertData = [NSData dataWithContentsOfFile:file]; // Returns nil
Any ideas?