iosobjective-ccocoa-touchuikituiactivityviewcontroller

How to share multiple urls via UIActivityViewController?


This is my code:

 NSArray* itemsToShare = [self itemsToShare:items]; // array of NSURLs

if (itemsToShare.count)
{
    UIActivityViewController* activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
    UIViewController*         controller = self.platformManager.sharePanel.navigationController.topViewController;
    [controller presentViewController:activityVC animated:YES completion:nil];
}

If itemsToShare.count is greater than 1 UIActivityViewController doesn't show Facebook and Twitter icons. If the array is filled with images it works correctly. What can I try next?


Solution

  • There is nothing you can do to change the standard Facebook and Twitter sharing extensions. Now that iOS 8 allows us to make custom extensions, we can see that these extensions decide for themselves which items they can handle.

    Apple's Extension programming guide discusses how an extension can specify which items it can handle. See Declaring Supported Data Types for a Share or Action Extension

    For example, to declare that your Share extension can support up to ten images, one movie, and one webpage URL, you might use the following dictionary for the value of the NSExtensionAttributes key:

    <key>NSExtensionAttributes</key>
        <dict>
            <key>NSExtensionActivationRule</key>
            <dict>
                <key>NSExtensionActivationSupportsImageWithMaxCount</key>
                <integer>10</integer>
                <key>NSExtensionActivationSupportsMovieWithMaxCount</key>
                <integer>1</integer>
                <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
                <integer>1</integer>
            </dict>
        </dict>
    

    So, what is probably happening here is that the Facebook and Twitter extensions specify that they can handle multiple images, but only one web URL, just like in Apple's example above.

    Since you can't change the Facebook or Twitter extensions, you will need to be creative in making your own mechanism for posting multiple links to Facebook at a time. Or consider whether its really that useful for users to post multiple links at once, rather than just posting them individually, as is the typical expected use case.