&tag(Cocoa); *目次 [#p4b126a5] #contents *関連ページ [#k4b803f5] *参考情報 [#ee6f19f7] *Tips [#lf79b4ab] **WebViewを設置した単純なネイティブアプリを作成する [#vbcce27a] **Objective-C + xibの場合 [#e25dd591] [[objective c - How to load URL on launch in a WebView (OSX project)? - Stack Overflow:http://stackoverflow.com/questions/15921974/how-to-load-url-on-launch-in-a-webview-osx-project]]に解説がある。 -xibのWindow内部のviewにWebViewをドロップ。 -xibとAppDelegateのソースコードを同時に表示して(アシスタントエディタを使う)、WebViewをControl-ドラッグする。するとAppDelegateにWebViewのアウトレットが自動で作成される。 -ヘッダーは以下のようになる。 #pre{{ #import <Cocoa/Cocoa.h> #import <WebKit/WebKit.h> @interface AppDelegate : NSObject <NSApplicationDelegate> @property (weak) IBOutlet WebView *myWebView; @end }} -ソースは以下のようになる。 #pre{{ #import "AppDelegate.h" @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application [[self.myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.softantenna.com/"]]]; } - (void)applicationWillTerminate:(NSNotification *)aNotification { // Insert code here to tear down your application } @end }} -プロジェクト設定でWebKit.frameworkを追加する。 -またATSのせいでHTTP接続ができない場合、Info.plistを修正する。「App Transport Security Settings > Allow Arbitary Loads」をYESにする。