Objective-c mac app - 打开外部URL

时间:2015-09-22 10:59:44

标签: ios objective-c

我正在尝试打开一个外部链接: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

0 个答案:

没有答案