在iPhone SDK上显示电子邮件生成器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在iPhone SDK上显示电子邮件生成器相关的知识,希望对你有一定的参考价值。
Add MessageUI.framework referencethen in header file
#import
#import
#import
// Displays an email composition interface inside the application. Populates all the Mail fields. MFMailComposeViewController *tempMailCompose = [[MFMailComposeViewController alloc] init]; tempMailCompose.mailComposeDelegate = self; //[tempMailCompose setToRecipients:[NSArray arrayWithObject:@"[email protected]"]]; //[tempMailCompose setCcRecipients:[NSArray arrayWithObject:@"[email protected]"]]; [tempMailCompose setSubject:@"iPhone App recommendation"]; [self presentModalViewController:tempMailCompose animated:YES]; [tempMailCompose release]; } // Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation. - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { // Notifies users about errors associated with the interface switch (result) { case MFMailComposeResultCancelled: NSLog(@"Result: canceled"); break; case MFMailComposeResultSaved: NSLog(@"Result: saved"); break; case MFMailComposeResultSent: NSLog(@"Result: sent"); break; case MFMailComposeResultFailed: NSLog(@"Result: failed"); break; default: NSLog(@"Result: not sent"); break; } [self dismissModalViewControllerAnimated:YES]; } // Launches the Mail application on the device. Workaround NSString *recipients = [NSString stringWithFormat:@"mailto:%@?subject=%@", @"[email protected]", @"iPhone App recommendation"]; email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } // Call this method and pass parameters -(void) showComposer:(id)sender{ Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); if (mailClass != nil){ // We must always check whether the current device is configured for sending emails if ([mailClass canSendMail]){ [self displayComposerSheet:sender]; }else{ [self launchMailAppOnDevice:sender]; } }else{ [self launchMailAppOnDevice:sender]; } }
以上是关于在iPhone SDK上显示电子邮件生成器的主要内容,如果未能解决你的问题,请参考以下文章
您可以使用 iOS6 SDK 构建但在 iPhone 5 上保持信箱吗?
从用户获取输入文本并使用 iPhone SDK 将其保存在网络服务器上
Iphone SDK:在 iphone 应用程序的后台发送电子邮件
如何捕获当前视图屏幕截图并在代码中重用? (iPhone SDK)