Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 10, 2011, 02:25 PM   #1
Danneman101
macrumors 6502
 
Join Date: Aug 2008
Help setting up webview

Do you know of any tutorial on how to set up a webview in a mac os x - app? Or any code-samples, perhaps?
Anything to get me from getting the damned "SIGABRT"-error I get all the time I try setting a webview-project up as described below:


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

@interface myAppDelegate : NSObject <NSApplicationDelegate> {
	// Declare:		WebView
	IBOutlet WebView *webView;
}
@property (assign) IBOutlet NSWindow *window;
// Set property:	WebView
@property (nonatomic, retain) IBOutlet WebView *webView;
@end

myAppDelegate.m
Code:
#import "myAppDelegate.h"
@implementation myAppDelegate
@synthesize window;
// Synt:	WebView
@synthesize webView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{	
	// LOAD WEBSITE
	NSString *urlAddress = @"http://www.iphonedevsdk.com";
	NSURL *url = [NSURL URLWithString:urlAddress];
	NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
	[webView loadRequest:requestObj];
}
@end

MainMenu.xib
- A webview is added to the window.
- The webview is then linked in the "Referencing Outlets" to the "my App Delegate" > "webView" that was declared in the h-file above.


Still I keep getting a "SIGABRT"-error (with no other info), so I guess Im doing something wrong...
Danneman101 is offline   0 Reply With Quote
Old Jan 10, 2011, 03:55 PM   #2
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
Run > Console. This will bring up the debugger console. Does your output contain the following?

Code:
*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView)
If it does, then you haven't linked your program to the WebKit framework. You can do that by:
  1. Right-clicking/control+clicking on the frameworks folder under your project in Xcode.
  2. Add > Existing Frameworks
  3. Select WebKit.framework
  4. Add

2 other things....

loadRequest: needs to be sent to webView's mainFrame, not it webView itself.

Code:
[[webView mainFrame] loadRequest:requestObj];
And according to the Memory Management of Nib Objects chapter of the Memory Management Programming Guide (1), outlets under Mac OS X should declared, differently to iOS outlets, like this:

Code:
@property (assign) IBOutlet UserInterfaceElementClass *anOutlet;
Note it's assign instead of nonatomic, retain.

(1) http://developer.apple.com/library/m...ibObjects.html
jiminaus is offline   0 Reply With Quote
Old Jan 10, 2011, 03:56 PM   #3
McGordon
macrumors member
 
Join Date: Dec 2010
Location: Scotland
If you forget to add the WebKit framework in Xcode, you'll get this:
Code:
2011-01-10 20:42:38.421 WebViewDemo[1031:a0b] An uncaught exception was raised
2011-01-10 20:42:38.423 WebViewDemo[1031:a0b] *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView)
2011-01-10 20:42:38.426 WebViewDemo[1031:a0b] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView)'
*** Call stack at first throw:
(
	0   CoreFoundation                      0x00007fff860cc7b4 __exceptionPreprocess + 180
	1   libobjc.A.dylib                     0x00007fff87f130f3 objc_exception_throw + 45
	2   CoreFoundation                      0x00007fff860cc5d7 +[NSException raise:format:arguments:] + 103
	3   CoreFoundation                      0x00007fff860cc564 +[NSException raise:format:] + 148
	4   Foundation                          0x00007fff858e2c9e _decodeObjectBinary + 2427
	5   Foundation                          0x00007fff858e3a1d -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1229
	6   Foundation                          0x00007fff858e3f5d -[NSArray(NSArray) initWithCoder:] + 462
	7   Foundation                          0x00007fff858e2d17 _decodeObjectBinary + 2548
	8   Foundation                          0x00007fff858e2191 _decodeObject + 208
	9   AppKit                              0x00007fff83a8901e -[NSView initWithCoder:] + 362
	10  Foundation                          0x00007fff858e2d17 _decodeObjectBinary + 2548
	11  Foundation                          0x00007fff858e2191 _decodeObject + 208
	12  AppKit                              0x00007fff83a973e3 -[NSWindowTemplate initWithCoder:] + 3824
	13  Foundation                          0x00007fff858e2d17 _decodeObjectBinary + 2548
	14  Foundation                          0x00007fff858e3a1d -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1229
	15  Foundation                          0x00007fff858e3460 -[NSSet(NSSet) initWithCoder:] + 447
	16  Foundation                          0x00007fff858e2d17 _decodeObjectBinary + 2548
	17  Foundation                          0x00007fff858e2191 _decodeObject + 208
	18  AppKit                              0x00007fff83a1910e -[NSIBObjectData initWithCoder:] + 1983
	19  Foundation                          0x00007fff858e2d17 _decodeObjectBinary + 2548
	20  Foundation                          0x00007fff858e2191 _decodeObject + 208
	21  AppKit                              0x00007fff83a1883d loadNib + 146
	22  AppKit                              0x00007fff83a17d9a +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 248
	23  AppKit                              0x00007fff83a17bd2 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 326
	24  AppKit                              0x00007fff83a15153 NSApplicationMain + 279
	25  WebViewDemo                         0x00000001000016a9 main + 33
	26  WebViewDemo                         0x0000000100001680 start + 52
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
sharedlibrary apply-load-rules all
kill
The key part being that it doesn't know the WebKit class:
2011-01-10 20:42:38.426 WebViewDemo[1031:a0b] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView)'

You said you only got SIGABRT and no other info. Are you sure you didn't get those exceptions logs and the stack trace as above?

Add the WebKit framework in Xcode and you'd get this:

2011-01-10 20:45:07.823 WebViewDemo[1077:a0b] -[WebView loadRequest:]: unrecognized selector sent to instance 0x10041a560

as you were sending loadRequest to webView instead of its main frame. This should have given you a compiler warning anyway.

Code:
//	change this
//	[webView loadRequest:requestObj];

//	to this
	[[webView mainFrame] loadRequest:requestObj];
Now it works and loads the page :-)

You've still got some strange things there, like a @property and @synthesize for window , but no instance variable to go with it.

Playing with WebView has been on my list of things to do as I learn Cocoa, so that was fun.
McGordon is offline   0 Reply With Quote
Old Jan 10, 2011, 04:15 PM   #4
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
Quote:
Originally Posted by McGordon View Post
You've still got some strange things there, like a @property and @synthesize for window , but no instance variable to go with it.
This would have come from the Cocoa application template, as is.

It does work. It works because, for the modern Mac OS X runtime (1), Objective-C will synthesise a instance variable if one isn't declared.

(1) http://developer.apple.com/library/m...Platforms.html
jiminaus is offline   0 Reply With Quote
Old Jan 10, 2011, 04:15 PM   #5
Danneman101
Thread Starter
macrumors 6502
 
Join Date: Aug 2008
Thank you both very much - seems you posted about the same time and gave overlapping advice

Yes, you're right - I totally forgot to include the framework :P Its been so long since I worked with xcode I forgot this has to be done.

Also, thanks for the tip about loading the webview, and how to properly assign properties
Danneman101 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Webview didFinishLoadForFrame DennisBlah Mac Programming 6 Mar 14, 2014 12:00 PM
YouTube and Webview issue DavidBlack Mac Programming 1 Feb 4, 2014 12:50 PM
Content Inset with WebView Blakeasd Mac Programming 2 Nov 30, 2013 10:27 PM
Can't Detect Events on a WebView Blakeasd Mac Programming 5 Nov 27, 2013 10:17 PM
WebView in Cocoa (Objective-C) tr!pf!3 Mac Programming 0 Aug 28, 2012 10:48 AM

Forum Jump

All times are GMT -5. The time now is 09:53 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC