- 追加された行はこの色です。
- 削除された行はこの色です。
&tag(Cocoa/WebViewの組み込み);
*目次 [#g8cf9e5e]
#contents
*関連ページ [#n7005997]
*参考情報 [#l5899f0b]
**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にする。