如何在运行时检测到已加载框架? [英] How do I detect, at runtime, that a framework has been loaded?

查看:95
本文介绍了如何在运行时检测到已加载框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个静态库以分发给其他人以用于iOS应用程序,其中,我想利用框架的优势,前提是框架已经被包含在应用程序中.我图书馆的用户.我已经弄清楚了如何编译该库,以便它本身不包含任何框架,但是一旦我尝试在应用程序中使用它,它就会失败,因为该库引用了不存在的框架.

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.

我不想强迫我的客户加载他们不需要的框架. 弱链接框架很酷,但这仅仅是意味着该框架不必存在于系统中(例如,对于旧版本的iOS);它的支持仍被编译为二进制文件.最好不要要求框架完全链接 ,并且仅在框架被链接时使用(可选).

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).

那么,有什么方法可以检测出运行时iOS应用中是否包含框架,而不仅仅是它是否存在于系统中?

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?

推荐答案

您可以使用

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

这篇关于如何在运行时检测到已加载框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆