0

In the text of a UITextView, I have an email address, and the dataDetectorType is set to dataDetectorTypeLink. Is there any way to set the subject line of an email with this configuration? I know how to set the subject line of an email using an MFMailComposeController, but is there a way to combine that with dataDetectorType?

EDIT: Here's my (re)definition of `openURL:(NSURL *)url in my app delegate:

-(void)openURL:(NSURL *)url
{
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"feedback on Gay Haiku"];
    [self presentViewController:mailer animated:YES completion:NULL];
}

But I get an error No visible @interface for AppDelegate declares the selectorpresentViewController:animated:`.

Joel Derfner
  • 2,207
  • 6
  • 33
  • 45

2 Answers2

1

Did you try appending ?subject= to the link?

@"mailto:webmaster@site.com?subject=Web Site Extraordinaire"

I just realize could use that only if you switched to a UIWebView... Is that an option?

EDIT:

The other way is to subclass UIApplication and override openURL:. This is described here.

Community
  • 1
  • 1
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Thanks so much. I created a subclass of `UIApplication` and included the code, but I get an error on the line `if ([self.delegate openURL:url])` that reads `No known instance method for selector 'openURL'`. What am I doing wrong? (Sorry--I'm still a little muddy on delegates....) – Joel Derfner Dec 12 '12 at 18:15
  • You need to implement the delegate method as well. – Mundi Dec 13 '12 at 00:23
  • So sorry for not understanding--but how do I do that? – Joel Derfner Dec 13 '12 at 12:43
  • I've added the (re)definition of `openURL`. – Joel Derfner Dec 13 '12 at 13:00
  • Yeah, you cannot present a view controller from the app delegate - just from another view controller. You have to send this message to a delegate of UIApplication which is a view controller. Maybe not so trivial, consider opening an new question. – Mundi Dec 13 '12 at 13:31
0

Since this seems to be fixed text that you control, you can add a NSLinkAttributeName attribute to the NSAttributedString at the range of your email address instead of enabling automatic link detection. This will let you specify the full URL that you want the system to open when the link is tapped. Then you can use Mundi's suggestion (include subject= in the URL) to set the subject of the email.

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15