webView

gal


Joined
Nov 4, 2012
Messages
3
Reaction score
0
Points
1
Hello,
i want to do that when i launch the program its automatically will open google web site in webView (for os x system).
i dont have prior knowledge of programming language and Xcode.
thanks !! :Blushing:
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
According to the developer documentation, you want the setMainFrameURL method (see here for more info). I don't have Xcode installed so I can't verify this but you might also be able to set this property when you design the interface.
 
OP
G

gal


Joined
Nov 4, 2012
Messages
3
Reaction score
0
Points
1
i created a new class with the name "webView" and i put this code:
[[webView MainFrame] loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:mad:"http://google.com"]]];
in AppDelegate.m in applicationDidFinishLaunching function and its says me "use of undeclared identifier 'webView' " but i set the identifier to 'webView'
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
You have to add the WebKit Framework to your project.

Secondly make sure you have an initialized instance of a WebView class.

only after that will your code work.

Also there is another WebView instance method, that only requires a URL String.
Code:
- (void)setMainFrameURL:(NSString *)URLString

Regards Mark
 
OP
G

gal


Joined
Nov 4, 2012
Messages
3
Reaction score
0
Points
1
...

thanks for everyone but it doesn't work..
here's my project (there isn't errors but it doesn't work):

G7k7F.png

J1lGX.png

UeiTm.png

jszDy.png

TbN2o.png
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Your code should be more something like this.

AppDelegate.h
Code:
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>
{
    IBOutlet WebView *webView;
    IBOutlet NSTextField *navbar;
    
    NSString *urlText;
}

@property (nonatomic, readonly, assign) IBOutlet NSWindow *window;

@property (nonatomic, readonly, retain)WebView *webView;
@property (nonatomic, readonly, retain)NSTextField *navbar;

@property (nonatomic, readwrite, copy)NSString *urlText;

- (IBAction)go:(id)sender;

@end

AppDelegate.m
Code:
#import "AppDelegate.h"

@implementation AppDelegate

@synthesize webView, navbar, urlText;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    
    urlText = [NSString stringWithFormat:@"http://www.Google.com"];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
}

- (IBAction)go:(id)sender
{
    urlText = [navbar stringValue];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
}

@end

There is a lot of things you have to do, to get this into a fully fledged browser, this is only
the very basic of code, with no error checking, and it assumes a lot, like the address typed
into your navbar is a correct address.

Also you need to implement the frame load delegate protocol, if you want to monitor the
web page loading progress, or check for network errors.

Try reading the Apple Developer documentation, relating to the WebKit Framework.

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/DisplayWebContent.html#//apple_ref/doc/uid/10000164i

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top