【问题标题】:Locking the Fields in MFMailComposeViewController锁定 MFMailComposeViewController 中的字段
【发布时间】:2011-09-11 04:37:43
【问题描述】:

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

基本上,我认为锁定字段而不是显示警报或“请不要编辑消息”的内容会更专业,因此如果无法锁定字段,这不是一个大问题,但任何帮助将不胜感激。

【问题讨论】:

  • 为什么不在后台发送邮件?并在“电子邮件已发送”完成时显示警报,如果您有兴趣,我可以分享一些代码。
  • @Louie ,如果可以的话,那就太好了,但是我听说 Apple 对后台电子邮件不满意?谢谢,杰克
  • 我知道有几个应用程序在后台通过电子邮件发送 - 我上周刚刚提交了我的应用程序,它应该会在接下来的一两天内进行“审查”,所以我会告诉你进展如何。同时我会格式化答案,以便其他人可以轻松看到。

标签: iphone ios email locking mfmailcomposeviewcontroller


【解决方案1】:

从下面的链接下载框架。然后我整理了一些代码,这些代码用一个很好的“请稍候”覆盖发送电子邮件。我附上了一张它在运行时的样子(它需要几秒钟)。请注意,我对创建 SMTP 框架没有任何功劳。它是在永远搜索后从互联网上下载的。 您可以下载的 zip 文件包括我为用户反馈创建的叠加图像。它同时具有@2x 和常规。您将不得不进入界面生成器并创建标签,尽管上面写着“发送试驾..”。它已经在代码中,但我没有从代码中添加它。所以你必须在IB中添加它。

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

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

3. 确保附上 UILabel 名称 界面生成器中的“loadingLabel”

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

Find Framework & Art here

对于您的 .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;

为您的 .m 文件包括:

@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 时)。它显示一条消息说它正在发送,然后在发送消息时“变亮”。

编码愉快!!

【讨论】:

  • 哦,是的!对不起!我忘了告诉你!好消息是我今天收到了苹果的回复,他们在应用程序中允许这样做。我的应用程序已获得批准。只是想你会想知道它的好去处!
  • 这是我在网上找到的 Gmail 设置 Gmail SMTP 服务器地址:smtp.gmail.com Gmail SMTP 用户名:您的完整 Gmail 地址(例如 me@gmail.com) Gmail SMTP 密码:您的 Gmail 密码Gmail SMTP 端口:465 需要 Gmail SMTP TLS/SSL:是
  • Apple 已接受我的 6 个使用此代码的应用程序。这不应该是一个问题。您的设置看起来正确。只需发送一条测试消息,看看它是否有效?
  • 您好,@Louie,请告诉我如何发送多封邮件,我的意思是与您的代码分组,您的代码中有 testMsg.toEmail,但没有抄送。和密件抄送请告诉这怎么可能提前谢谢
  • @Louie- 指向您的代码的链接会引发 404 错误。你不再提供了吗?
猜你喜欢
  • 1970-01-01
  • 2018-02-10
  • 1970-01-01
  • 1970-01-01
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多