我想知道如何通过电子邮件发送webview链接。然后,当收件人收到电子邮件时,他们可以在safari中打开链接。提前谢谢!
我把这个BOOL放在我的代表中
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([[[request URL] scheme] isEqual:@"mailto"]) {
[[UIApplication sharedApplication] openURL:[request URL]]; return NO;
}
return YES;
}
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:@"", nil]];
[composer setSubject:@""];
[composer setMessageBody:webview isHTML:YES];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
}
答案 0 :(得分:1)
您在商家信息中做了两件不同的事情:
如果您想在点击网络视图中的MFMailComposeViewController
链接时显示mailto:
,则代码的第一部分(shouldStartLoadWithRequest
)应该有效,除非您愿意必须将isEqual
更改为isEqualToString
:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if ([[[request URL] scheme] isEqualToString:@"mailto"]) { //Change in this line
[[UIApplication sharedApplication] openURL:[request URL]]; return NO;
}
return YES;
}
(请注意,用户在使用时会离开您的应用)
如果您想发送用户点击给某人的链接,您可以使用类似
的内容-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:@"", nil]];
[composer setSubject:@"Link"];
[composer setMessageBody:request.URL isHTML:YES];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
}
return YES;
}
答案 1 :(得分:0)
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:@"", nil]];
[composer setSubject:@""];
[composer setMessageBody:webview.request.URL.absoluteString isHTML:YES];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
}
else
[composer release];
}
}