スキップしてメイン コンテンツに移動

XcodeでWebKitアプリ。

昨日のエントリー「MacGapとUKI。」が気になってソースを追いかけた。なかなか良かった。もうMacGapを使う事になるだろうけど、独自でWebKitフレームワークを組み込んだアプリを作る時のメモとして簡単な手順をブログに残しておく。

作り方の手順。

  1. Xcodeで新規プロジェクト作成。プロジェクトテンプレートはCocoa Aplicationを選択。
  2. 任意のプロジェクト情報を記入。
  3. TARGETSでアプリを選択、SummaryのLinked Frameworks and LibrariesでWebKit.framewokを追加。
  4. MainMenu.xibをクリック。続いてWindowをクリック。
  5. Object LibraryでWeb Viewを選択しウインドウに張り付け。
  6. Size inspectorでリサイズ可能に設定。
  7. アプリを開いた時に設定した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
  8. コーディング後、MainMenu.xibでコード内容をWev Viewにコネクトする。
設定したURLを開くサンプルコードを載せておく。

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;

@end
AppDelegate.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

コメント

このブログの人気の投稿

私はcodecademy.comの日本語翻訳を開始した

http://www.codecademy.com/ が  http://codeyear.com/ を軸に動き出したようだ。CodecademyはJavaScriptの初学はもちろんプログラミングの入門にも最適だ。これを英語圏だけにとどめておくにはあまりにもおしい。 そこで勝手ながら Mylingual を利用して日本語訳をあてることにした。自分の時間が許す限り翻訳していこうと思う。

デスクトップアプリの一つの形。 Mozilla Labs >> Chromeless Browser

動画:デスクトップを消し去るウェブブラウザ Webian Shell、Mozilla Chromeless ベース -- Engadget Japanese : "話が複雑になってきましたが、要はウェブアプリ時代を迎え、従来のデスクトップアプリを一掃するハイパーシンプルなフルスクリーンブラウザがリリースされたということ。" 古い記事だが、その当時自分は記事を鵜呑みにしてフルスクリーンブラウザが出来たんだ、くらいにしか思っていなかった。しかしMacGap、Fluidなどweb開発技術でのデスクトップアプリ作成を調べていくうちに、この記事が表面上のことにしか触れていない事がわかった。Web ShellとはChromelessのリファレンス実装でもあったのだ。 ではChromelessとは何か? ChromelessとはXULRunnerアプリをhtml、javascript、cssで書けるフレームワークだ。