【发布时间】:2012-08-28 06:54:43
【问题描述】:
我是 iphone 开发新手。我正在构建一个可以发送电子邮件的应用程序。我正在使用以下代码
- (IBAction)btnsendPressAction:(id)sender {
if([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailer=[[MFMailComposeViewController alloc]init];
mailer.mailComposeDelegate=self;
[mailer setSubject:@"A Message for testing"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"rajshetty2125@gmail.com", @"secondMail@example.com", nil];
[mailer setToRecipients:toRecipients];
UIImage *image=[UIImage imageNamed:@"logo.png"];
NSData *imageData=UIImagePNGRepresentation(image);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"logo.png"];
NSString *emailBody=@"This is test email";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
mailer.modalPresentationStyle = UIModalPresentationPageSheet ;
}
else{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"failure" message:@"Alert" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
我的问题是 mailComposeController 委托没有被调用,我无法通过我的应用程序发送电子邮件。我浏览了许多链接,但每个地方都找到了相同的方法。谁能帮我解决这个问题?
【问题讨论】:
-
我还在我的代码中添加了代理的正确方法,我没有放在这里。
-
检查您使用的设备中是否配置了邮件ID。
-
我正在测试我的模拟器,我可以知道如何配置吗?
-
好的,您将无法通过模拟器发送邮件并在设备中进行配置:support.apple.com/kb/ht4810
-
这意味着我无法在模拟器中测试它??
标签: objective-c ios xcode email mfmailcomposeviewcontroller