How do I detect, at runtime, that a framework has

2019-07-31 10:48发布

I'm building a static library to distribute to other folks to use in iOS apps, wherein I'd like to take advantage of of frameworks only if they have been included in the app by the users of my library. I've figured out how to compile the library so that it does not itself include any frameworks, but as soon as I try to use it in an app, it fails, because the library references frameworks that don't exist.

I'd rather not force my clients to load frameworks they don't need. Weak-linking frameworks is cool, but that just means that the framework doesn't have to be present on the system (e.g., for older versions of iOS); its support is still compiled into the binary. Better would be not to require the framework to be linked at all, and only use it if it is linked (optionally or not).

So, is there any way to detect that a framework is included in an iOS app at runtime, not just whether it's present on the system?

1条回答
成全新的幸福
2楼-- · 2019-07-31 11:30

you can use

if (NSClassFromString(@"FrameworkClass") == nil) {
   // the framework is not available
} else {
   // the framework is avaiable
}
查看更多
登录 后发表回答