【发布时间】:2014-06-05 20:45:41
【问题描述】:
我是制作 iOS 应用程序的初学者。我制作了一个简单的 webview 来显示我的网页。问题是在我的网页中按下的每个链接都会在 webview 中打开。我想在 safari 中打开一些链接。我希望在 webview 中打开以“..something”开头的链接,并在 safari 中打开所有其他链接。我还有一个用于电子邮件和拨号的按钮,我想在手机上的拨号应用程序和电子邮件应用程序中打开它。这是一种可能吗?请简单解释一下。
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIWebView *webView;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize webView;
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:@"http://MyWebPage"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我在下面的代码中使用 java 为 android 制作了相同的应用程序
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try{
System.out.println("url called:::" + url);
if (url.startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
} else if (url.startsWith("http:")
|| url.startsWith("https:")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
} else if (url.startsWith("mailto:")) {
MailTo mt=MailTo.parse(url);
send_email(mt.getTo());
}
else {
return false;
}
}catch(Exception e){
e.printStackTrace();
}
return true;
}
}
【问题讨论】: