如何使用WebKit在cocoa应用程序中显示网站(例如苹果)?

时间:2011-03-28 21:01:05

标签: macos webkit

好的,到目前为止,我已经按照其他人的答案对整个事情进行了编码,但是当我构建并运行我的项目时,我在代码中指定的网站或html文件不会显示在屏幕上;只显示一个白色屏幕。

这是我到目前为止在头文件中所做的:

//MY HEADER FILE(.h):

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface Project_XAppDelegate: NSObject <NSApplicationDelegate> {
NSWindow *window;
IBOutlet WebView *webView;
}

@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet WebView *webView;

@end

实现:

//MY IMPLEMENTATION FILE(.m):

#import "Project_XAppDelegate.h"
#import "WebKit/Webkit.h"

@implementation Project_XAppDelegate

@synthesize window;
@synthesize webView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}

- (void)awakeFromNib {
    NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
    NSString *htmlPath = [resourcesPath stringByAppendingString:@"/Users/*****/Desktop/Project X/HTML/mehmar.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
}

@end

1 个答案:

答案 0 :(得分:0)

您的htmlPath对我来说不对。不太熟悉OSX开发,但是一旦你获得了bundle路径,你就不应该只为它添加“index.html”而不是磁盘上文件的完整路径。

试试[resourcesPath stringByAppendingString:@"index.html"]