锁定 MFMailComposeViewController 中的字段 [英] Locking the Fields in MFMailComposeViewController

查看:24
本文介绍了锁定 MFMailComposeViewController 中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能以某种方式锁定 MFMailComposeViewController 中的字段,以便用户无法更改正文、收件人等?我需要用户发送到特定帐户的电子邮件和正文以满足某些标准,因此如果用户彻底编辑格式,一切都可能会出现可怕的错误..目前,正文是根据用户的数据填写的前一个视图中文本字段和日期选择器的输入.

Is it possible to somehow lock the fields in an MFMailComposeViewController so that the body, recipients etc cannot be changed by the user? I need the e-mail the user sends to go to a particular account and the body to meet certain criteria so if the user drastically edits the format everything could go horribly wrong..At the moment the body is filled in from data that the user inputs to textfields and date-pickers in the previous view.

基本上我认为锁定字段会更专业,而不是显示警报或说请不要编辑消息",所以如果字段不能被锁定,这不是一个大问题,但任何帮助将不胜感激.

Basically I think it would just be more professional to have the fields locked rather than display an alert or something saying "Please Don't Edit the Message", so its not a massive problem if the fields can't be locked, but any help would be greatly appreciated.

推荐答案

从下面的链接下载框架.然后我将一些代码放在一起,发送带有漂亮的请稍候"覆盖的电子邮件.我附上了它运行时的样子(它需要几秒钟).请注意,我不会因为创建 SMTP 框架而受到赞扬.它是在永久搜索后从互联网上下载的.您可以下载的 zip 文件包括我为用户反馈创建的覆盖图像.它同时具有@2x 和常规.您将不得不进入界面构建器并创建标签,尽管上面写着发送试驾......".它已经在代码中,但我没有从代码中添加它.所以你必须在IB中添加它.

Download the framework from the link below. Then I have put together some code that sends the email with a nice "please wait" overlay. I have attached an image of what this looks like while its running (for the few seconds it takes). Please note, I take no credit for creating the SMTP framework. It was downloaded from the internet after searching for it forever. The zip file that you can download includes the overlay images that I created for user feedback. It has both @2x and regular. You will have to go into interface builder and create the label though that says "sending test drive..". Its already in the code but I didnt add it from code. So youll have to add it in IB.

1. 确保添加您的框架下载到您的项目中.

1. Make sure to add the framework you downloaded to your project.

2. 确保将 CFNetwork 框架添加到您的项目中

2. Make sure to add the CFNetwork framework to your project

3. 确保附上 UILabel 名称界面构建器中的loadingLabel"

3. Make sure to attach the UILabel name "loadingLabel" in interface builder

4. 用户名和密码代码所指的是一个smtp服务器.如果你没有一个创造一个 Gmail 帐户并使用 gmail设置.如果你不熟悉使用 Gmail 设置谷歌gmailsmtp"你会找到你需要的.

4. The username and password that the code is refering to is an smtp server. If you dont have one create a gmail account and use gmail settings. If you are not familiar with gmail settings google "gmail smtp" you will find what you need.

查找框架&艺术在这里

对于您的 .h 文件,请确保包括:

For your .h file make sure to include:

//for sending email alert
UIActivityIndicatorView * spinner;
UIImageView * bgimage;
IBOutlet UILabel * loadingLabel;

}
@property (nonatomic, retain)IBOutlet UILabel * loadingLabel;
@property (nonatomic, retain)UIImageView * bgimage;
@property (nonatomic, retain)UIActivityIndicatorView * spinner;
-(void)sendEmail;
-(void)removeWaitOverlay;
-(void)createWaitOverlay;
-(void)stopSpinner;
-(void)startSpinner;

对于您的 .m 文件,包括:

For your .m file include:

@synthesize bgimage,spinner,loadingLabel;

// add this in ViewDidLoad
//set loading label to alpha 0 so its not displayed
loadingLabel.alpha = 0;

其他的都是自己的功能

-(void)sendEmail {


    // create soft wait overlay so the user knows whats going on in the background.
    [self createWaitOverlay];

    //the guts of the message.
    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
    testMsg.fromEmail = @"youremail@email.com";
    testMsg.toEmail = @"targetemailaddress@email.com";
    testMsg.relayHost = @"smtpout.yourserver.net";
    testMsg.requiresAuth = YES;
    testMsg.login = @"yourusername@email.com";
    testMsg.pass = @"yourPassWord";
    testMsg.subject = @"This is the email subject line";
    testMsg.wantsSecure = YES; // smtp.gmail.com doesn't work without TLS!



    // Only do this for self-signed certs!
    // testMsg.validateSSLChain = NO;
    testMsg.delegate = self;

    //email contents
    NSString * bodyMessage = [NSString stringWithFormat:@"This is the body of the email. You can put anything in here that you want."];


    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                               bodyMessage ,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

    testMsg.parts = [NSArray arrayWithObjects:plainPart,nil];

    [testMsg send];

}


- (void)messageSent:(SKPSMTPMessage *)message
    {
    [message release];

    //message has been successfully sent . you can notify the user of that and remove the wait overlay
    [self removeWaitOverlay];



    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Sent" message:@"Thanks, we have sent your message"
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
}

- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error
{
    [message release];
    [self removeWaitOverlay];

    NSLog(@"delegate - error(%d): %@", [error code], [error localizedDescription]);

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email Error" message:@"Sending Failed - Unknown Error :-("
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
}



-(void)createWaitOverlay {

    // fade the overlay in
    loadingLabel = @"Sending Test Drive...";
    bgimage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
    bgimage.image = [UIImage imageNamed:@"waitOverLay.png"];
    [self.view addSubview:bgimage];
    bgimage.alpha = 0;
    [bgimage addSubview:loadingLabel];
    loadingLabel.alpha = 0;


    [UIView beginAnimations: @"Fade In" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationDuration:.5];
    bgimage.alpha = 1;
    loadingLabel.alpha = 1;
    [UIView commitAnimations];
    [self startSpinner];

    [bgimage release];

}

-(void)removeWaitOverlay {

    //fade the overlay out

    [UIView beginAnimations: @"Fade Out" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationDuration:.5];
    bgimage.alpha = 0;
    loadingLabel.alpha = 0;
    [UIView commitAnimations];
    [self stopSpinner];


}

-(void)startSpinner {

    spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinner.hidden = FALSE;
    spinner.frame = CGRectMake(137, 160, 50, 50);
    [spinner setHidesWhenStopped:YES];
    [self.view addSubview:spinner];
    [self.view bringSubviewToFront:spinner];
    [spinner startAnimating];
}

-(void)stopSpinner {

    [spinner stopAnimating];
    [spinner removeFromSuperview];
    [spinner release];

}

最终结果如下所示.屏幕看起来有点暗(有点像显示 UIAlert 时).它显示一条消息说它正在发送,然后在发送消息时变亮".

The final results are shown below. The screen appears to dim a bit (kind of like when an UIAlert is shown). It shows a message saying its being sent, and then "brightens" back up when the message is sent.

快乐编码!!

这篇关于锁定 MFMailComposeViewController 中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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