user2936528
user2936528

Reputation: 51

Open mailto links within my app Instead of Mail app

I have gone all over here and the web and nothing I have implemented has worked. I am building an iPhone app using UIWebview because it was best suited for this project.

My goal is that when I tap on a mailto link it will bring up the MFMailComposeViewController instead of opening the Mail app. Because I have tried all solutions that I could find I have two thoughts.

  1. In iOS7 is this no longer possible? I cannot imagine that this is the case but I have noticed that most of the ideas and tutorials I find on this are primarily from a few years back.

  2. Did I possibly set up my UIWebview and delegates wrong? I am putting a link to a screenshot in case that is the case.

Any help is appreciated. I'd share all the links to things I have tried but my rating isn't high enough yet to pile on the links.

Thanks for the help.

Screenshot

EDIT

I am still wrestling with this issue. I thought I was closer, but still can't get this to work. The goal is still to call MFMailComposeViewController from inside the UIWebview. Let me give some more specifics. 1. I am using a mailto form.

  1. I am using an image surrounded by an anchor tag as my submit button with some javascript to make it submit.

  2. The form submits and the mail app comes up fine.

  3. I thought maybe my problem was that this was not a true mailto link so I tried this. MY HTML

    <a href="inapp://javascript:void(0)" class="intruder"><img src="button.png" /></a>
    

My ViewController.m code

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.scheme isEqualToString:@"inapp"]) {
    if ([request.URL.host isEqualToString:@"javascript:void(0)"]) {



        if ([MFMailComposeViewController canSendMail]) {

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


            mailer.mailComposeDelegate = self;

            [mailer setToRecipients:[NSArray arrayWithObject:request.URL.resourceSpecifier]];


            NSString *body = @"";


            [mailer setMessageBody:body isHTML:NO];


            [self presentModalViewController:mailer animated:YES];

        }


        return NO;
    }
    return YES;
}

}

Everything is still opening in the Mail App though. Any ideas?

Upvotes: 2

Views: 743

Answers (1)

user2936528
user2936528

Reputation: 51

I figured it out. I hadn't set the webview delegate properly. I thought I had in my header file. Then I set the delegate to self in my viewdidload method and everything worked.

I had tried that before and I guess I typed something wrong because my file wouldn't load. Anyways got everything to work now.

Upvotes: 1

Related Questions