锁定MFMailComposeViewController中的字段

Jac*_*ins 24 email iphone locking ios mfmailcomposeviewcontroller

是否有可能以某种方式锁定字段,MFMailComposeViewController以便用户无法更改正文,收件人等?我需要用户发送的电子邮件去特定帐户和身体符合某些标准,所以如果用户大幅度编辑格式,一切都可能会出现可怕的错误.当时正文从用户的数据填充输入到上一个视图中的文本字段和日期选择器.

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

Lou*_*uie 43

从以下链接下载框架.然后我把一些代码发送到一起,发送电子邮件时有一个很好的"请等待"覆盖.我附上了一张图片,显示了它在运行时的样子(需要几秒钟).请注意,我不赞成创建SMTP框架.它是在永久搜索后从互联网上下载的.您可以下载的zip文件包括我为用户反馈创建的叠加图像.它有@ 2x和常规.您将不得不进入界面构建器并创建标签,尽管说"发送测试驱动器......".它已经在代码中,但我没有从代码中添加它.所以你必须在IB中添加它.

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

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

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

4.代码所引用的用户名和密码是smtp服务器.如果您没有创建一个Gmail帐户并使用Gmail设置.如果您不熟悉gmail设置google"gmail smtp",您将找到所需内容.

在这里找到框架和艺术

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

//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;
Run Code Online (Sandbox Code Playgroud)

对于您的.m文件包括:

@synthesize bgimage,spinner,loadingLabel;

// add this in ViewDidLoad
//set loading label to alpha 0 so its not displayed
loadingLabel.alpha = 0;
Run Code Online (Sandbox Code Playgroud)

其他一切都是它自己的功能

-(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];

}
Run Code Online (Sandbox Code Playgroud)

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

快乐编码!!

在此输入图像描述

  • 哦,是的!抱歉!我忘了告诉你!好消息是我今天收到了苹果公司的回复,他们在应用程序中允许这样做.我的应用已被批准.只是觉得你想知道它的好去! (7认同)
  • 以下是我在网上找到的Gmail设置Gmail SMTP服务器地址:smtp.gmail.com Gmail SMTP用户名:您的完整Gmail地址(例如me@gmail.com)Gmail SMTP密码:您的Gmail密码Gmail SMTP端口:465 Gmail SMTP TLS /需要SSL:是的 (3认同)
  • 您好,@ Louie,请告诉我如何发送多个邮件,我的意思是在您的代码组中,您的代码中有testMsg.toEmail,但没有CC.和BCC请告诉我这是如何可能的事先谢谢 (3认同)
  • @Louie-代码的链接会引发404错误.你不再提供它吗? (2认同)