2

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];
    }
}
Undo
  • 25,519
  • 37
  • 106
  • 129
Brandon
  • 2,163
  • 6
  • 40
  • 64
  • Why don't you lean on `SLComposeViewController`'s builtin alert(s)? You get this when you always present, so not check with `isAvailableForServiceType`. – meaning-matters May 30 '13 at 12:31
  • Hey, I used your code for showing alert in my app. working fine without any problem I thing you're doing something wrong above code NOT in completion handler. – Rivan Mar 28 '14 at 09:42

0 Answers0