Skip to content

Instantly share code, notes, and snippets.

@tfrank64
Created March 7, 2014 00:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tfrank64/9403006 to your computer and use it in GitHub Desktop.
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