1
votes

I have an actionsheet created, and I want to display the Facebook sharing option. I dont want to use the Composeviewcontroller. My question is: Is it possible to only show the Facebook share option if the user has IOS6 installed? Code snippets would be very useful. I added the social framework and created an actionsheet with some buttons:

UIActionSheet *actionsheet = [[UIActionSheet alloc] initWithTitle:@"Empfehlen" delegate:(id)self cancelButtonTitle:@"Abbrechen" destructiveButtonTitle:nil otherButtonTitles:@"via Mail", @"via iMessage/SMS",@"Tweet", nil];

Does have anyone suggestions or solutions what to do?

My App uses iOS 5 and I would like to keep it.

Thanks.

2
You may also wish to use a UIActivityViewController on iOS 6 instead of a UIActionSheet. - rmaddy
I mean exactly what I said. Have a look at the docs for UIActivityViewController. It's the new way to present these types of options. On an iOS 6 device, run the Photos app and choose to share a photo for an example. The popup with all the icons is a UIActivityViewController. Much nicer than showing an action sheet. - rmaddy
well yes, youre right, but what is if the user doesnt use ios6? like on Iphone 3gs? - MasterRazer
See my answer below to see how you use either a UIActivityViewController or UIActionSheet depending on the user's device. - rmaddy

2 Answers

4
votes

This is an answer to a follow-up question made by the OP in the comments section.

Under iOS 6+ you can use a UIActivityViewController while under iOS 5 earlier you can still use a UIActionSheet.

Class avcClass = NSClassFromString(@"UIActivityViewController");
if (avcClass) {
    NSArray *items = @[ xxx ]; // create one or more activity item objects for this
    UIActivityViewController *avc = [[avcClass alloc] initWithActivityItems:items applicationActivities:nil];
    [self presentViewController:abc animated:YES completion:nil];
} else {
    // create and show an action sheet
}
2
votes

UIActionSheet *actionsheet;

if([SLComposeViewController class] != nil)//some class only available in ios6
{
    actionsheet = [[UIActionSheet alloc] initWithTitle:@"Empfehlen" delegate:(id)self 
cancelButtonTitle:@"Abbrechen" destructiveButtonTitle:nil otherButtonTitles:@"via Mail", @"via iMessage/SMS",@"Tweet", @"Facebook", nil];
}
else
{
    actionsheet = [[UIActionSheet alloc] initWithTitle:@"Empfehlen" delegate:(id)self 
cancelButtonTitle:@"Abbrechen" destructiveButtonTitle:nil otherButtonTitles:@"via Mail", @"via iMessage/SMS",@"Tweet", nil];
}

You're just checking if what you want to share exists and if it does show the option.