简体   繁体   English

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

[英]How to import Social framework only for iOS 6?

How to import Social framework only for iOS 6? 如何仅为iOS 6导入社交框架? I want to disable the Social Framework for other iOS versions. 我想为其他iOS版本禁用社交框架。 Currently I am trying this and I also tried to change the FrameWork to optional, But not running on iOS 5.1 simulator. 目前,我正在尝试此操作,并且还尝试将FrameWork更改为可选,但无法在iOS 5.1模拟器上运行。

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

Please tell how to check and run for both iOS 5 and iOS 6. Thanks. 请告诉我们如何检查和运行iOS 5和iOS6。谢谢。

Firstly: don't query the OS version for guessing what is supported, check if a particular feature is actually available instead of using it based on assumptions. 首先:不要查询操作系统版本以猜测支持什么,请检查某个特定功能是否确实可用,而不是根据假设使用它。

That said, recent versions of iOS and the toolchain support weak linking. 也就是说,最新版本的iOS和工具链支持弱链接。 Just check for the class you're intending to use is not Nil (method #1). 只需检查您打算使用的类不是Nil (方法1)即可。 You can also use the Objective-C runtime for this (method #2): 您也可以为此使用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
}

For weak linkage to take effect, the frameworks you intend to use like this shall be added as "optional" instead of as "required". 为使弱链接生效,应将打算使用的框架添加为“可选”,而不是“必需”。 If you don't use Xcode or an IDE but only a command line toolchain, weak linkage can be enforced by passing 如果您不使用Xcode或IDE,而仅使用命令行工具链,则可以通过传递以下信息来强制执行弱链接

-flat_namespace -undefined dynamic_lookup

to the linker. 链接器。

#import <Avaibility.h>

#if defined(__IPHONE_6_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
#import <Social/Social.h>
#import <Accounts/Accounts.h>
#elif defined(__IPHONE_5.0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#else
#error Your SDK is too old ! Need at least 5.0.
#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM