Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Native iOS7 Sharing Dialogs
// Not full implementation for UIActionSheet, check out my blog for more details: http://cleancrispcode.wordpress.com/
// shareTitles array created in viewDidLoad
NSArray *shareTitles = @[NSLocalizedString(@"Facebook", nil), NSLocalizedString(@"Twitter", nil)];
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:shareTitles[0]])
[self shareContentOfType:SLServiceTypeFacebook];
else if ([buttonTitle isEqualToString:shareTitles[1]])
[self shareContentOfType:SLServiceTypeTwitter];
}
// Uses native sharing dialogs for serviceType passed in.
- (void)shareContentOfType:(NSString *)serviceType
{
// Determines if service has been activated through Settings app.
if ([SLComposeViewController isAvailableForServiceType:serviceType])
{
SLComposeViewController *sharingSheet = [SLComposeViewController composeViewControllerForServiceType:serviceType];
NSString *message = NSLocalizedString(@"Check out this app and stuff", nil);
[sharingSheet setInitialText:[NSString stringWithFormat:@"%@ %@", message, @"[AppStoreURL]"]];
[self presentViewController:sharingSheet animated:YES completion:Nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment