#pragma mark - email
- (void)showMailPicker
{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil) {
if ([mailClass canSendMail]) {
[self displayMailComposerSheet];
}else{
[self launchMailAppOnDevice];
}
}else{
[self launchMailAppOnDevice];
}
}
- (void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void)launchMailAppOnDevice
{
NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=my email!";
//@"mailto:support@shichangit.com?subject=意见与反馈"
NSString *body = @"&body=";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSString *msg;
switch (result)
{
case MFMailComposeResultCancelled:
msg = @"邮件发送取消";
break;
case MFMailComposeResultSaved:
msg = @"邮件保存成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultSent:
msg = @"邮件发送成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultFailed:
msg = @"邮件发送失败";
[self alertWithTitle:nil msg:msg];
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)alertWithTitle:(NSString *)title msg:(NSString *)message
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)showMailPicker
{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil) {
if ([mailClass canSendMail]) {
[self displayMailComposerSheet];
}else{
[self launchMailAppOnDevice];
}
}else{
[self launchMailAppOnDevice];
}
}
- (void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void)launchMailAppOnDevice
{
NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=my email!";
//@"mailto:support@shichangit.com?subject=意见与反馈"
NSString *body = @"&body=";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSString *msg;
switch (result)
{
case MFMailComposeResultCancelled:
msg = @"邮件发送取消";
break;
case MFMailComposeResultSaved:
msg = @"邮件保存成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultSent:
msg = @"邮件发送成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultFailed:
msg = @"邮件发送失败";
[self alertWithTitle:nil msg:msg];
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)alertWithTitle:(NSString *)title msg:(NSString *)message
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}