Skip to content

Instantly share code, notes, and snippets.

@aaronwardle
Last active December 18, 2015 22:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aaronwardle/5854403 to your computer and use it in GitHub Desktop.
Save aaronwardle/5854403 to your computer and use it in GitHub Desktop.
UIActivityViewController Example
- (void)shareButtonClicked {
//-- set strings and URLs
NSString *textObject = @"Information that I want to tweet or share";
NSString *urlString = [NSString stringWithFormat:@"http://www.mygreatdomain/%@", _selectedPageString];
NSURL *url = [NSURL URLWithString:urlString];
NSArray *activityItems = [NSArray arrayWithObjects:textObject, url, nil];
//-- initialising the activity view controller
UIActivityViewController *avc = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
avc.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard ];
//-- define the activity view completion handler
avc.completionHandler = ^(NSString *activityType, BOOL completed){
if (completed) {
// NSLog(@"Selected activity was performed.");
} else {
if (activityType == NULL) {
// NSLog(@"User dismissed the view controller without making a selection.");
} else {
// NSLog(@"Activity was not performed.");
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment