How to import Social framework only for iOS 6?

喜夏-厌秋 提交于 2019-12-17 16:31:32

问题


How to import Social framework only for iOS 6? I want to disable the Social Framework for other iOS versions. Currently I am trying this and I also tried to change the FrameWork to optional, But not running on iOS 5.1 simulator.

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.


回答1:


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. Just check for the class you're intending to use is not Nil (method #1). You can also use the Objective-C runtime for this (method #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

-flat_namespace -undefined dynamic_lookup

to the linker.




回答2:


#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


来源:https://stackoverflow.com/questions/14002304/how-to-import-social-framework-only-for-ios-6

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