我正在尝试打开一个外部链接:google.com但我不能,有人能说我的代码中我做错了吗?
有人可以解释为什么默认情况下会阻止外部链接?
AppDelegate.m
#import "AppDelegate.h"
#import <WebKit/WebKit.h>
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet WebView *webview;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
NSURL*url=[NSURL URLWithString:@"HTML/content.htm"];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
NSURL*url = [[NSURL alloc]initWithString:@"http://google.com/" ];
[[UIApplication sharedApplication] openURL:url];
NSURL *htmlFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HTML/content" ofType:@"htm"] isDirectory:NO];
request = [NSURLRequest requestWithURL:htmlFile];
[[self.webview mainFrame] loadRequest:request];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
return YES;
}
@end