I have a third party API that I am trying to integrate into my iOS Universal application. The API works fine if ran on a device but throws me a compile time link error when trying to run it on the simulator. So, is there a way I can skip their static library linking if I run on the simulator?
Thanks
Actually, It's a lot easier than I thought.
Step 1: Add the linker flags -ObjC and -all_load to your target. This tells the objc runtime that even if we don't reference a class in code, it will still load it into memory.
Step 2: In your code, you can do this:
Class cls = NSClassFromString(@"SomeClassInStaticLibrary");
if (cls == nil)
{
// on the simulator
}
else
{
// on the device, use the class like usual
id myInstance = [[cls alloc] init];
}
Unfortunately, you have to refer to everything as an id, because if you include the headers, you WILL get a linker error.
Its a bit of a hack, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With