我正在尝试通过MFMailComposeViewController发送一个自定义网址方案,以便收件人可以点击嵌入式链接并在他的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上打开我的应用程序。 出于某种原因,当此链接嵌入到电子邮件中时,点击它不会执行任何操作。 有帮助吗? 感谢
答案 0 :(得分: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];