The Social
framework (SLComposeViewController
) was only introduced in iOS 6. In iOS 5 the only native connection to any social network was Twitter and the TWTweetComposeViewController
class. iOS 6 introduced the Social
framework with pre-existing Twitter support and new Facebook and Sina Weibo integration.
So on iOS 5 you cannot actually make any reference or call to SLComposeViewController
, you will need to use conditions to see which version (iOS 5 or 6) the user's device is running then make any operations/conditions.
The code if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
is used to see if the user has setup a Facebook account in the Settings application.
Yes, so you add the Twitter
framework for iOS 5 compatibility, make sure Social
framework is set to optional by the way.
To check what version the device is running, add this to your MyApp-Prefix.pch
file:
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
Then you can use it in any class because the prefix file is automatically imported to all classes:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0") && SYSTEM_VERSION_LESS_THAN(@"6.0")) {
NSLog(@"This is called when device is running iOS 5, 5.0.1, 5.1 etc.");
}
else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
NSLog(@"iOS 6.0, 6.0.1, 6.0.2, 6.1 etc.");
}