Skip to content

Instantly share code, notes, and snippets.

@tfrank64 tfrank64/sharing.m
Created Mar 7, 2014

What would you like to do?
Native iOS7 Sharing Dialogs
// Not full implementation for UIActionSheet, check out my blog for more details:
// 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.