MasterRazer
MasterRazer

Reputation: 1377

Show button on actionsheet, if IOS 6 installed

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.

Upvotes: 1

Views: 1386

Answers (2)

rmaddy
rmaddy

Reputation: 318794

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
}

Upvotes: 4

rooster117
rooster117

Reputation: 5552

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.

Upvotes: 2

Related Questions