单击电子邮件地址时设置默认主题 [英] Set default subject when click on email address

查看:95
本文介绍了单击电子邮件地址时设置默认主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using dataDetectorTypes property with UITextView.code works fine.

当我点击链接时,电子邮件编辑器会出现预填充的To:[email address]但是我想要设置默认主题:[主题字符串]。

When I click on link email composer appears with pre-filled To:[email address] but i want to set default Subject:[subject string] also.

我该怎么做?

推荐答案

1)拳头将< UITextViewDelegate,MFMailComposeViewControllerDelegate> 添加到包含textview的类中。

1)Fist add <UITextViewDelegate, MFMailComposeViewControllerDelegate> to the class that contains the textview.

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

You must add two imports to this class:

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

2)添加变量: MFMailComposeViewController (在这个示例mailVC中,您还可以将其添加为.h)中的类属性。

2) Add a variable: MFMailComposeViewController (in this example mailVC, you can also add it as a class property in your .h)

3)实现下一个方法:

3) Implement the next method:

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

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

This allows to intercepts the specific url interaction. You can cancel a specific interaction and add your own action, for example:

-(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变量:

3) To dismiss your MFMailComposeViewController variable:

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

这对我有用!

这篇关于单击电子邮件地址时设置默认主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆