Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make WebView OSX Xcode project load a URL on launch?

Okay, well I am trying to learn how to develop mac apps. I have done making a web browser and all, but I really want to know how to make the WebView load a URL (lets say http://google.com/) when the apps start. How do I do that?

like image 485
0x60 Avatar asked Jan 24 '11 00:01

0x60


1 Answers

In your app delegate, implement

-(void)applicationDidFinishLaunching:(NSNotification*) notification
{
     ....
}

This method is called automatically by the Cocoa system when the app did finish launching, quite obvious, right?

Suppose you have IBOutlet WebView*webview in your app delegate. Then all you have to do is, inside applicationDidFinishLaunching:, to call

 NSURL*url=[NSURL URLWithString:@"http://www.google.com"];
 NSURLRequest*request=[NSURLRequest requestWithURL:url];
 [[webview mainFrame] loadRequest:request];

That's all!

like image 115
Yuji Avatar answered Sep 16 '22 12:09

Yuji