So I\'m trying out the new UIActivityViewController in iOS 6, and it\'s really easy to get up and running, but I can\'t figure out how to control it like I want
If you don't specifically need to use UIActivityViewController using SLComposeViewController is easy to use for this purpose.
+(void)presentShareWidgetWithText:(NSString*)text url:(NSURL*)url images:(NSArray*)images toService:(NSString*)service presentIn:(UIViewController*)parentViewController {
SLComposeViewController* controller = [SLComposeViewController composeViewControllerForServiceType:service];
if (controller == nil) {
DLog(@"Could not initialize SLComposeViewController for %@!", service);
return;
}
if (url != nil) {
if (![controller addURL:url])
DLog(@"Failed adding url %@!", url);
}
if (images != nil) {
for (UIImage* image in images) {
if (![controller addImage:image]) {
DLog(@"Failed adding image: %@", image);
}
}
}
if (![controller setInitialText:text]) {
DLog(@"Failed setting initial text: %@", text);
}
SLComposeViewControllerCompletionHandler handler = ^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
DLog(@"SLComposeViewControllerResultCancelled");
break;
case SLComposeViewControllerResultDone:
DLog(@"SLComposeViewControllerResultDone, Shared on service: %@", service);
break;
default:
DLog(@"Unhandled result: %d", result);
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
[parentViewController dismissViewControllerAnimated:YES completion:^{
DLog(@"Dismissed a controller here!");
}];
});
};
[controller setCompletionHandler:handler];
[parentViewController presentViewController:controller animated:YES completion:^{
DLog(@"Presented %@!", controller);
}];
}