Question

I've tried searching endlessly and I can't find a solution. I want to allow my user to share and image and some text through Facebook, Twitter, SMS, and Email. I can't seem to get UIActivityViewController to work correctly though.

First off:

  1. I am testing on a device not the sim
  2. I have Facebook and Twitter account setup in Settings

Here is how I create UIActivityViewController:

- (IBAction)shareSelected:(id)sender {

    NSMutableArray *activityItems;

    //Add an image if one exist
    if (self.property.images.count > 0) {

        UIImageView *imageView = (UIImageView*)[self.scrollView panelAtIndex:0];

        if (imageView.image)
            [activityItems addObject:imageView.image];

    }

    //Set text
    [activityItems addObject:[NSString stringWithFormat:@"I like this property! %@", [self addressCityStateZipFormatted]]];

    //Set URL
    [activityItems addObject:[NSURL URLWithString:@"http://www.google.com"]];

    //Create controller
    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    activityController.excludedActivityTypes = @[UIActivityTypePrint,
                                                 UIActivityTypeCopyToPasteboard,
                                                 UIActivityTypeAssignToContact,
                                                 UIActivityTypeSaveToCameraRoll];

    //Present
    [self presentViewController:activityController
                       animated:YES completion:nil];

}

However, this is all that gets displayed on my device: Here is an image description

I don't understand why it's not showing any options and why it's full screen instead of action sheet size height.

Was it helpful?

Solution

You aren't initializing activityItems:

NSMutableArray *activityItems;

Change it to

NSMutableArray *activityItems = [NSMutableArray array];

and you may have more success.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top