Linux配置url,给iPhone app的email内容中添加URL

Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));

if (mailClass != nil)

{

/ We must always check whether the current device is configured for sending emails

if ([mailClass canSendMail])

{

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

[picker setSubject:NSLocalizedString(@"My blog!",nil)];

// Set up recipients

NSArray *toRecipients = [NSArray arrayWithObject:self.emailAddress];

[picker setToRecipients:toRecipients];

NSString *blogLink =[NSString stringWithFormat:

@"my blog",@"zhoushu",8606];

NSString *body=[NSString stringWithFormat:NSLocalizedString(@"This is test! Check  my blog with this link:%@",nil),blogLink];

[picker setMessageBody:body isHTML:YES];

[self presentModalViewController:picker animated:YES];

[picker release];

}

(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), googleMapLink,myLocation.latitude,myLocation.longitude,myLocation.altitude];

NSString *email=[NSString stringWithFormat:@"%@%@",recipients,body];

//URL一定要用NSUTF8StringEncoding方法编码才能用的哦~

email=[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];

// 真机测试成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值