0

我正在尝试通过 MFMailComposeViewController 发送自定义 url 方案,以便收件人可以点击嵌入式链接并在他的 iphone 上打开我的应用程序。到目前为止,收件人收到了一封电子邮件,但当他点击 LINK 时没有任何反应。这是代码:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
[picker setSubject:@"Incoming task"];
// Fill out the email body text
NSString * types = @"";
for(NSString *type in task.location_types){
    types = [types stringByAppendingFormat:@"%@|",type];
}
if(types.length > 1){
    types = [types substringToIndex:types.length - 1];
}
NSString *desc = [task.description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *link = [NSString stringWithFormat:@"helpy://?taskid=%d&desc=%@&types=%@\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:@"<a href=\"#\" onclick=\"doSomething();\">TAP HERE</a><script type=\"text/javascript\" charset=\"utf-8\">function doSomething() { window.location = \"%@\;return false;}</script>",link];


[picker setMessageBody:emailBody isHTML:YES]; 

picker.navigationBar.barStyle = UIBarStyleBlack;

[controller presentModalViewController:picker animated:YES];
[picker release];

helpy://?taskid=..... 是我自定义注册的 URL 方案,如果我从浏览器的地址栏中键入它,它会在 iPhone 上打开我的应用程序。出于某种原因,当这个链接嵌入到电子邮件中时,点击它不会做任何事情。有什么帮助吗?谢谢

4

1 回答 1

1

我非常怀疑 Mail 是否会在 iOS 上执行 JavaScript(即使在桌面上我也非常怀疑,但还没有尝试过)。只需将 URL 设置为href超链接的属性,一切都会正常工作。你为什么要使用 JavaScript 来做这件事?我只是好奇 ;-)

NSString *link = [NSString stringWithFormat:@"helpy://?taskid=%d&desc=%@&types=%@\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:@"<a href=\"%@\">TAP HERE</a>", link];
于 2012-10-04T18:21:37.797 回答