我正在使用带有UITextView.code的dataDetectorTypes属性。
当我点击链接电子邮件时,编辑器出现预先填写的收件人:[电子邮件地址],但我想设置默认主题:[主题字符串]。
我该怎么做?
答案 0 :(得分:2)
1)拳头将<UITextViewDelegate, MFMailComposeViewControllerDelegate>
添加到包含textview的类中。
您必须向此类添加两个导入:
#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];
}
这对我有用!
答案 1 :(得分: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];
}