0

I'm trying to send via MFMailComposeViewController a custom url scheme so that the receipient could tap on the embedded link and open my application on his iphone. So far the receipient gets an email but nothing happens when he taps on the LINK. here is the code:

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=..... is my custom registered URL Scheme and if I type it from the address bar of the browser it opens up my application on the iPhone. For some reason when this link is embedded into email, tapping it does not do anything. Any help? thanks

Eli Barzilay
  • 29,301
  • 3
  • 67
  • 110
Gal Blank
  • 2,070
  • 2
  • 18
  • 18

1 Answers1

1

I highly doubt that Mail will execute JavaScript on iOS (even on the desktop I highly doubt it, but haven't tried it though). Simply set the URL as the href attribute of your hyperlink and everything should work fine. Any reason why you want to do it with JavaScript? I'm just curious ;-)

NSString *link = [NSString stringWithFormat:@"helpy://?taskid=%d&desc=%@&types=%@\"",task.TaskId,desc,types];
NSString *emailBody = [NSString stringWithFormat:@"<a href=\"%@\">TAP HERE</a>", link];
Björn Kaiser
  • 9,882
  • 4
  • 37
  • 57
  • Thanks, I turned to javascript because the simple a href didn't work, finally the solution apparently to set it via url link ( just like you proposed and I tried earlier ) the only thing is it WILL NOT work in Simulator for some reason and Works on real device, that's why I could not figure this one out, I was testing it on simulator. – Gal Blank Oct 04 '12 at 18:26