0

我正在使用带有 UITextView.code 的 dataDetectorTypes 属性工作正常。

当我单击链接时,电子邮件作曲家会出现预先填写的收件人:[电子邮件地址],但我也想设置默认主题:[主题字符串]。

我怎样才能做到这一点?

4

2 回答 2

2

1)拳头添加 <UITextViewDelegate, MFMailComposeViewControllerDelegate>到包含文本视图的类。

您必须向此类添加两个导入:

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

2)添加一个变量:(MFMailComposeViewController在这个例子mailVC中,你也可以将它作为一个类属性添加到你的.h中)

3)实现下一个方法:

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange

这允许拦截特定的 url 交互。您可以取消特定交互并添加自己的操作,例如:

-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
   //EXAMPLE CODE
    if ([[URL scheme] isEqualToString:@"mailto"]) {

        mailVC = [[MFMailComposeViewController alloc] init];
        [mailVC setToRecipients:@[@"your@destinationMail.com"]];
        [mailVC setSubject:@"A subject"];
        mailVC.mailComposeDelegate = self;

        [self presentViewController:mailVC animated:YES completion:^{
           // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        }];
        return NO;
    }
    return YES;
}

3) 要关闭您的 MFMailComposeViewController 变量:

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    [mailVC dismissViewControllerAnimated:YES completion:nil];
}

这对我行得通!

于 2015-07-01T17:01:16.043 回答
1
    MFMailComposeViewController *mailController =    [[MFMailComposeViewController alloc] init]; 

   mailController.mailComposeDelegate = self;

if([MFMailComposeViewController canSendMail]){
    [mailController setSubject:@"Subject"];
    [mailController setMessageBody:@"Email body here" isHTML:NO]; 
    [mailController setMessageBody:[self getInFo] isHTML:YES]; 
    [mailController setToRecipients:[NSArray arrayWithObject:@"xx@xxx.com"]];
    [mailController setTitle:@"Title"];

    [self presentModalViewController:mailController animated:YES]; 
}else{
    [mailController release];
}
于 2012-04-11T10:46:26.677 回答