如何仅为iOS 6导入社交框架?

HDd*_*per 1 iphone ios ios5 ios6

如何仅为iOS 6导入社交框架?我想为其他iOS版本禁用社交框架.目前我正在尝试这个,我也尝试将FrameWork更改为可选,但不在iOS 5.1模拟器上运行.

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
        {
          #import <Social/Social.h>   
        }
Run Code Online (Sandbox Code Playgroud)

请告诉我们如何检查和运行iOS 5和iOS 6.谢谢.

小智 18

首先:不要查询操作系统版本以猜测支持的内容,检查特定功能是否实际可用而不是基于假设使用它.

也就是说,iOS的最新版本和工具链支持弱链接.只是检查你打算使用的课程不是Nil(方法#1).您也可以使用Objective-C运行时(方法#2):

// method #1 - weak linking
if ([SLRequest class] != Nil) {
    // Social.framework is available
}

// method #2 - querying the runtime
if (NSClassFromString(@"SLRequest") != Nil) {
    // Social.framework is available
}
Run Code Online (Sandbox Code Playgroud)

要使弱链接生效,您打算使用的框架应添加为"可选"而不是"必需".如果您不使用Xcode或IDE但只使用命令行工具链,则可以通过传递强制执行弱链接

-flat_namespace -undefined dynamic_lookup
Run Code Online (Sandbox Code Playgroud)

到链接器.