// header file // importing the MessageUI framework #import <MessageUI/MessageUI.h> // adding the delegate functionality to the class (<MFMailComposeVIEwControllerDelegate>) @interface TutorialProjectVIEwController : UIVIEwController <MFMailComposeVIEwControllerDelegate> { } - (IBAction)presstheMailbuttonDudefunction:(ID)sender// Implementation file - (IBAction)presstheMailbuttonDudefunction:(ID)sender { // allocatind new message composer window MFMailComposeVIEwController *mc = [[MFMailComposeVIEwController alloc] init]; // setting a delegate method to "self" mc.mailComposeDelegate = self; // pre-populating the message subject [mc setSubject:@"Send me a message"]; // adding content of the message as a plain text [mc setMessageBody:@"Send me a message is you like this tutorial :)" isHTML:NO]; // adding content of the message as an HTML [mc setMessageBody:@"<p>Send me a message is you like this tutorial :)<p>" isHTML:YES]; // adding recipIEnts [mc setToRecipIEnts:[NSArray arrayWithObjects:@"Fuerte <info@fuerte.cz>",@"info@xprogress.com",nil]]; // adding recipIEnts for a send copy to (arrayWithObject or arrayWithObjects) [mc setCcRecipIEnts:[NSArray arrayWithObject:@"test@example.com"]]; // adding hIDden recipIEnts [mc setBccRecipIEnts:[NSArray arrayWithObject:@"test@example.com"]]; // adding image attachment // getting path for the image we have in the tutorial project Nsstring *path = [[NSBundle mainBundle] pathForResource:@"Extra_Xcode_100x100" ofType:@"png"]; // loading content of the image into NSData NSData *imageData = [NSData dataWithContentsOffile:path]; // adding the attachment to he message [mc addAttachmentData:imageData mimeType:@"image/png" filename:@"Collection"]; // setting different than the default Transition for the modal vIEw controller [mc setModalTransitionStyle:UIModalTransitionStyleCrossdissolve]; /* Modal vIEw controllers Transitions: UIModalTransitionStyleCoverVertical => pops up from the bottom,default Transition UIModalTransitionStyleCrossdissolve => fade on the screen UIModalTransitionStyleFlipHorizontal => page flip */ // displaying our modal vIEw controller on the screen (of course animated has to be set on YES if you want to see any Transition) [self presentModalVIEwController:mc animated:YES]; // releasing the controller [mc release]; } // delegate function callback - (voID)mailComposeController:(MFMailComposeVIEwController *)controller dIDFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { // switchng the result switch (result) { case MFMailComposeResultCancelled: NSLog(@"Mail send canceled."); /* Execute your code for canceled event here ... */ break; case MFMailComposeResultSaved: NSLog(@"Mail saved."); /* Execute your code for email saved event here ... */ break; case MFMailComposeResultSent: NSLog(@"Mail sent."); /* Execute your code for email sent event here ... */ break; case MFMailComposeResultFailed: NSLog(@"Mail send error: %@.",[error localizedDescription]); /* Execute your code for email send Failed event here ... */ break; default: break; } // hIDe the modal vIEw controller [self dismissModalVIEwControllerAnimated:YES]; }
而且我没有得到正确的答案……这是一个正确的代码吗?
解决方法 >确保将MessageUI框架包含在iOS项目中.在Xcode 4中,您可以通过在左栏中选择项目来包含框架.然后选择“构建阶段”选项卡.在这里,您可以单击“link Binary With librarIEs”左侧的箭头,您将看到已包含在您的应用程序中的框架列表.如果缺少MessageUI.framework – 只需将其添加到那里.>您发布的代码看起来像一个完整的教程代码剪切…所以只使用您需要的代码…并逐步添加更多功能.通过这种方式,您可以看到添加错误代码行的位置.也许您的应用包中没有图片“Extra_Xcode_100x100.png”.
所以,这是一个“最小”的MFMailComposeVIEwController:
- (IBAction)showMinimalModalMailVIEw:(ID)sender { // get a new new MailComposeVIEwController object MFMailComposeVIEwController *mc = [[MFMailComposeVIEwController alloc] init]; // his class should be the delegate of the mc mc.mailComposeDelegate = self; // set a mail subject ... but you do not need to do this :) [mc setSubject:@"This is an optional mail subject!"]; // set some basic plain text as the message body ... but you do not need to do this :) [mc setMessageBody:@"This is an optional message body plain text!" isHTML:NO]; // set some recipIEnts ... but you do not need to do this :) [mc setToRecipIEnts:[NSArray arrayWithObjects:@"first.address@test.com",@"second.address@test.com",nil]]; // displaying our modal vIEw controller on the screen with standard Transition [self presentModalVIEwController:mc animated:YES]; // be a good memory manager and release mc,as you are responsible for it because your alloc/init [mc release]; }总结
以上是内存溢出为你收集整理的使用iPhone上的MessageUI中的MFMailComposeViewController从应用程序发送电子邮件消息全部内容,希望文章能够帮你解决使用iPhone上的MessageUI中的MFMailComposeViewController从应用程序发送电子邮件消息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)