简体   繁体   中英

iOS app mailto href link will only work with long press

I have a very basic <a href="mailto:test@gmail.com">E-mail here</a> link in my HTML source for an iOS app.

The link shows up fine, but when I click it on the simulator or on the device the compose message doesn't show up. If I long press on the link, I get the options for New Message, Add to Contacts, and Copy. If I select New Message, everything works as expected. Pressing once on the link doesn't do anything.

I've looked around and tried various things, but this is as simple seeming as it gets. Other links throughout the app work (telephone numbers, embedded PDF resources, etc.) as intended. Mailto just won't work as expected.

Any ideas?

After a while I figured it out. It had to do with the way I was handling link clicks in the - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType method.

I had to make sure and add the line [[UIApplication sharedApplication] openURL:[request URL]]; in the correct spot of that method. For me, since I wanted the compose mail view to show up inside of my app, I used MFMailComposeViewController .

It works now, but doesn't really explain why long press still works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM