-1

我正在开发一个应用程序,但我错过了一小部分。我准备了一个视图,以便您可以将数据插入 UITextField,然后我可以通过电子邮件发送此信息。我尝试了很多方法。

#import <UIKit/UIKit.h>
@interface RMAcpu : UIViewController <UITextFieldDelegate> 
@property  IBOutlet UITextField *prodotto;
@property  IBOutlet UITextField *seriale;
@property  IBOutlet UITextField *cfiva;
@property  IBOutlet UITextField *email;
@property  IBOutlet UITextField *problema;
- (IBAction)inviodati:(id)sender;
@end

关于.m,我试过了,但没有发送信息。你能帮我通过电子邮件发送信息吗?

#import "RMAcpu.h"

@interface RMAcpu ()

@end

@implementation RMAcpu
@synthesize prodotto;
@synthesize seriale;
@synthesize cfiva;
@synthesize email;
@synthesize problema;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [self setProdotto:nil];
    [self setSeriale:nil];
    [self setCfiva:nil];
    [self setEmail:nil];
    [self setProblema:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)inviodati:(id)sender {
    NSString *stringaMail = [NSString stringWithFormat:@"mailto:cristian@prokoo.com", [[prodotto text] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], [[seriale text] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], [[cfiva text]  stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];


    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:stringaMail]];



}
@end
4

1 回答 1

1

除非您实现自己的 SMTP 客户端,否则您不能直接从您的应用程序发送电子邮件。遵循这种方法的当前项目是skpsmtpmessage

如果您不想以这种方式尝试,则需要使用框架中的MFMailComposeViewController 。MessageUI这将允许您创建电子邮件模板并预填充收件人、主题和邮件正文等字段,但用户必须手动点击发送按钮。

于 2012-07-17T08:04:33.843 回答