How do I detect, at runtime, that a framework has been loaded?

余生长醉 提交于 2019-12-11 09:26:23

问题


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:


you can use

if (NSClassFromString(@"FrameworkClass") == nil) {
   // the framework is not available
} else {
   // the framework is avaiable
}


来源:https://stackoverflow.com/questions/22704151/how-do-i-detect-at-runtime-that-a-framework-has-been-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!