我使用dataDetectorTypes财产与UITextView.code工作正常。
当我点击链接的电子邮件作曲家出现带有预填充:[电子邮件地址],但我想设置默认主题:[主题字符串]也。
我怎样才能做到这一点?
我使用dataDetectorTypes财产与UITextView.code工作正常。
当我点击链接的电子邮件作曲家出现带有预填充:[电子邮件地址],但我想设置默认主题:[主题字符串]也。
我怎样才能做到这一点?
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];
}
这对我行得通!
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];
}