昨日のエントリー「MacGapとUKI。」が気になってソースを追いかけた。なかなか良かった。もうMacGapを使う事になるだろうけど、独自でWebKitフレームワークを組み込んだアプリを作る時のメモとして簡単な手順をブログに残しておく。
作り方の手順。
AppDelegate.h
作り方の手順。
- Xcodeで新規プロジェクト作成。プロジェクトテンプレートはCocoa Aplicationを選択。
- 任意のプロジェクト情報を記入。
- TARGETSでアプリを選択、SummaryのLinked Frameworks and LibrariesでWebKit.framewokを追加。
- MainMenu.xibをクリック。続いてWindowをクリック。
- Object LibraryでWeb Viewを選択しウインドウに張り付け。
- Size inspectorでリサイズ可能に設定。
- アプリを開いた時に設定したURLを開くにはコーディングが必要。参考URL「How to launch a web page on opening of the application」http://stackoverflow.com/questions/8599175/how-to-launch-a-web-page-on-opening-of-the-application
- コーディング後、MainMenu.xibでコード内容をWev Viewにコネクトする。
AppDelegate.h
// // AppDelegate.h // MyWebBrowser // // Created by ryo on 12/01/12. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. // #import <Cocoa/Cocoa.h> #import <WebKit/WebKit.h> @interface AppDelegate : NSObject <NSApplicationDelegate> @property (assign) IBOutlet NSWindow *window; @property (retain, nonatomic) IBOutlet WebView *webview; @endAppDelegate.m(httpプロトコル)
//
// AppDelegate.m
// MyWebBrowser
//
// Created by ryo on 12/01/12.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize webview = _webview;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *urlAddress = @"https://docs.google.com/?browserok=true";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[self.webview mainFrame] loadRequest:requestObj];
}
@end
AppDelegate.m(ローカルリソース)//
// AppDelegate.m
// MyWebBrowser
//
// Created by ryo on 12/01/12.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize webview = _webview;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"public_html"];
NSURL *url = [NSURL fileURLWithPath:filepath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[self.webview mainFrame] loadRequest:requestObj];
}
@end
コメント
コメントを投稿