Created
March 7, 2014 00:58
-
-
Save tfrank64/9403006 to your computer and use it in GitHub Desktop.
Native iOS7 Sharing Dialogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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