【问题标题】:iOs Custom scheme in MFMailComposeViewControllerMFMailComposeViewController 中的 iOs 自定义方案
【发布时间】:2012-10-05 02:30:48
【问题描述】:

我正在尝试通过 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 上打开我的应用程序。 出于某种原因,当这个链接嵌入到电子邮件中时,点击它不会做任何事情。 有什么帮助吗? 谢谢

【问题讨论】:

    标签: objective-c ios url mfmailcomposer


    【解决方案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];
    

    【讨论】:

    • 谢谢,我转向 javascript,因为简单的 a href 不起作用,最终解决方案显然是通过 url 链接设置它(就像你提出的,我之前尝试过)唯一的就是它会由于某种原因不能在模拟器中工作并且在真实设备上工作,这就是为什么我无法弄清楚这一点,我正在模拟器上测试它。
    猜你喜欢
    • 1970-01-01
    • 2014-04-02
    • 2014-10-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多