Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController with HTML

When I pass a string containing HTML content as an array element to the UIActivityViewController initWithActivityItems method it doesn't present it as HTML in the selected 'share' controller, but instead presents the HTML source (i.e. the markup rather than interpreting it).

And while I can understand why it would do this for share targets that don't support html content, it won't interpret it for things like email either, which do (previously this would be done by setting the isHTML property to YES on the MFMailComposeController).

Should I waste my time creating a UIActivityItemProvider that returns custom content based on the 'activity type' or is there really no way to get the mail controller presented by the UIActivityViewController to interpret the content as HTML?

like image 996
Christopher King Avatar asked Sep 30 '12 02:09

Christopher King


1 Answers

In my testing if the string begins "<html><body>" and ends "</body></html>" then it is treated as HTML.

If you want a good result with the non-HTML-aware sharing services you need to instead use an object that implements the UIActivityItemSource protocol and returns the HTML string when from -activityViewControllerPlaceholderItem: and from -activityViewController:itemForActivityType: if the activity is UIActivityTypeMail and nil otherwise.

A second UIActivityItemSource that returns a suitable non-HTML string from -activityViewControllerPlaceholderItem: and from -activityViewController:itemForActivityType: if the activity is not UIActivityTypeMail (and nil if it is) is the rest of the puzzle.

I recommend against having one object do both jobs, as the UIActivity engine is entitled to make different decisions based on whether the placeholder item appears to be HTML or not.

like image 174
Phil Willoughby Avatar answered Nov 07 '22 17:11

Phil Willoughby