业精于勤,荒于嬉
全部博文(763)
分类:
2010-09-09 09:55:31
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
/ We must always check whether the current device is configured for sending emails
}
(2)方法二:用text link方法打开email链接:-(void)openURL:@"mailto://";
用MFMailComposeViewControllerDelegate的另一个好处就是在给email的body添加的URL信息可以导入外来数字/字符串,而openURL方法添加时就会出现URL无法正确显示的问题?看到下面这个例子你就明白了。
NSString *toRecipients = self.emailAddress;
NSString *recipients = [NSString stringWithFormat:NSLocalizedString(@"mailto:%@?&subject=My location!",nil),toRecipients ];
NSString *googleMapLink =[NSString stringWithFormat: @"location"];
//上面这个链接能正确显示,但是如果要加载位置信息就无法在email中正确显示了,如
NSString *body = [NSString stringWithFormat:NSLocalizedString(@"&body=My location is:%@(latitude=%f,longitude=%f,altitude=%f)",nil),
NSString *email=[NSString stringWithFormat:@"%@%@",recipients,body];
//URL一定要用NSUTF8StringEncoding方法编码才能用的哦~
email=[email stringByAddingPercentEsc
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];