我正在使用 dataDetectorTypes 属性与 UITextView.code 工作正常。
当我单击链接时,电子邮件编辑器会显示预填充的“收件人:[电子邮件地址]”,但我也想设置默认主题:[主题字符串]。
我怎样才能做到这一点?
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:@[@"[email protected] /cdn-cgi/l/email-protection"]];
[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];
}
这对我行得通!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)