I am trying to perform the simple task of displaying a cancelled or successful alert that depends on whether or not a user has posted or cancelled a share. I am using the iOS 6 sharing capability as outlined below:
NSArray *activityItems = @[textToShare, urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController
alloc]initWithActivityItems:activityItems applicationActivities:nil];
[activityVC setExcludedActivityTypes:[NSArray arrayWithObjects:
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeSaveToCameraRoll,
nil]];
[self presentViewController:activityVC animated:TRUE completion:nil];
I can get a cancelled/successful alert to work by using the SLServiceType for Facebook as outlined below, but I cannot seem to get this to work for the simple activityVC version above. Any help would be appreciated!
- (IBAction)facebookPost:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *mySLComposerSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:@"Sample Share"];
[mySLComposerSheet addImage:[UIImage imageNamed:@"myImage.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:@"http://www.website.com"]];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case 0:
{
SLComposeViewControllerResultCancelled:
NSLog(@"Post Canceled");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Cancelled"
message:@"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
break;
}
case 1:
{
SLComposeViewControllerResultDone:
NSLog(@"Post Sucessful");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Successful"
message:@"You must be connected to the internet to use this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
break;
}
default:
break;
}
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
}