Send a link in an email using UIActivityViewController

Chris picture Chris · Oct 19, 2013 · Viewed 9.9k times · Source

How do I send an email using UIActivityViewController with a quick message and a link? I have tried using an NSURL:

NSURL *url = [NSURL URLWithString:@"http://google.com/"];

And an NSString:

// String with Hyperlink syntax
NSString *stringURLHyperlink = @"<a href=\"http://google.com/">Google</a>";

// Plain text link out of desperation.
NSString *stringURLPlain = @"http://google.com/"; 

I am not using a custom UIActivity. The NSString/NSURL are being sent as activityItems:

NSArray *activityItems = @[link];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];

Thanks everyone.

EDIT 1:

My apologies, I should have made my question clearer. How can I send a message and a clickable link in an email using UIActivityViewController?

Answer

ccjensen picture ccjensen · Oct 23, 2013

This seems to work fine in iOS 7:

[[UIActivityViewController alloc] initWithActivityItems:@[@"<html><body><b>This is a bold string</b><br\\>Check out this amazing site: <a href='http://apple.com'>Apple</a></body></html>"] applicationActivities:nil];

If you share an object that conforms to the UIActivityItemSource protocol, then you will be able to specify what the email's subject should be too!

tl;dr: Use basic html in an NSString to wrap the desired email contents