Search code examples
iosobjective-cuiactivityviewcontrolleruipopover

UIActivity popover: How to show only one row of symbols?


My app should send a picture to a server when a button is pressed. I choose to use AirDrop for this, and want the UI to be as simple as possible. Now I can exclude all activities except AirDrop, but still the popover looks quite messy:

enter image description here

How can I get rid of the two extra lines? They serve no purpose.

If it helps, here is the method which is called when the button is tapped:

- (IBAction)orderButtonTapped:(UIButton *)sender {

    UIImage *image   = [self.detailViewController.paint extractImageFromBitmap];
    UIDevice *device = UIDevice.currentDevice;
    NSArray *items   = @[device.name, image];
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items
                                                                                         applicationActivities:nil];
    activityViewController.excludedActivityTypes = @[UIActivityTypePostToFacebook,
                                                     UIActivityTypePostToTwitter,
                                                     UIActivityTypePostToWeibo,
                                                     UIActivityTypeMessage,
                                                     UIActivityTypeMail,
                                                     UIActivityTypePrint,
                                                     UIActivityTypeCopyToPasteboard,
                                                     UIActivityTypeAssignToContact,
                                                     UIActivityTypeSaveToCameraRoll,
                                                     UIActivityTypeAddToReadingList,
                                                     UIActivityTypePostToFlickr,
                                                     UIActivityTypePostToVimeo,
                                                     UIActivityTypePostToTencentWeibo];
    activityViewController.popoverPresentationController.sourceView = self.view;

// if iPhone
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        [self presentViewController:activityViewController animated:YES completion:nil];
    }

// if iPad
    else {
        CGFloat xPos = self.orderButton.frame.origin.x + self.orderButton.frame.size.width/2;
        CGFloat yPos = self.orderButton.frame.origin.y;
        UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
        [popup presentPopoverFromRect:CGRectMake(xPos, yPos, 0, 0)
                               inView:self.view
             permittedArrowDirections:UIPopoverArrowDirectionAny
                             animated:YES];
    }
}

Solution

  • You can’t. User can have custom 3rd party Activities there. You can’t whitelist only selected activities (e.g. AirDrop), but only blacklist some of them. Which is what you are already doing.