Search code examples
iosxcode4sigabrt

SIGABRT on UIApplicationMain error


I have searched and searched and despite being a lot of topics on this issue, i cannot find any relevant to solve my issue. If someone could please take a look:

I am using xcode 4.6

I am getting the error in the main.m file at the int retVal

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

My ReaderSampleViewController.h file looks like this:

@interface ReaderSampleViewController
    : UIViewController
    // ADD: delegate protocol
    < ZBarReaderDelegate >
{
    UIImageView *resultImage;
    UITextView  *resultText;

}
@property (nonatomic, retain) IBOutlet UIImageView *resultImage;
@property (nonatomic, retain) IBOutlet UITextView  *resultText;
- (IBAction) scanButtonTapped;
@end

And ReaderSampleViewController.m file looks like this:

#import "ReaderSampleViewController.h"

@implementation ReaderSampleViewController

@synthesize resultImage, resultText;

- (IBAction) scanButtonTapped
{
    // ADD: present a barcode reader that scans from the camera feed
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    // present and release the controller
    [self presentViewController: reader animated:NO completion:nil];
    [reader release];
}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;

    // EXAMPLE: do something useful with the barcode data
    resultText.text = symbol.data;
    // QR CODE TO THE WEBSITE
    #define IS_IPAD    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    #define IS_IPHONE  (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)




    //----------- STYLE AND AUTO SIZE THE WEB VIEW

    float widthScreen, heightScreen; //xScreen, yScreen
    if(IS_IPAD){

        widthScreen  = 768.0;
        heightScreen = 960.0;
       // xScreen      = 360.0;
       // yScreen      = 500.0;
        UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"LoaderIpad.jpg"]];
        self.view.backgroundColor = background;
        [background release];
    }else{
    //CGRect webFrame = CGRectMake(0.0, 0.0, 360.0, 480.0);
        widthScreen  = 320.0;
        heightScreen = 490.0;
     //   xScreen      = 150.0;
     //   yScreen      = 190.0;
        UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"LoaderIphone.jpg"]];
        self.view.backgroundColor = background;
        [background release];
   }

    CGRect webFrame = CGRectMake(0.0, 0.0, widthScreen, heightScreen);



    UIWebView *webView= [[UIWebView alloc] initWithFrame:webFrame];
    webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    webView.scalesPageToFit = NO;
    webView.autoresizesSubviews = YES;

    [webView setBackgroundColor:[UIColor clearColor]];
    //[webView setOpaque:NO];



    //--------- GET THE URL
    NSString *urlAddress= @"";
    urlAddress =[urlAddress stringByAppendingString:resultText.text];
    NSURL *url= [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj= [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    [self.view addSubview:webView];
    [webView release];

    // EXAMPLE: do something useful with the barcode image
    resultImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    //resultImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];


    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissViewControllerAnimated:NO completion:nil];
}

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orient
{
    return(YES);
}


- (void) dealloc {
    self.resultImage = nil;
    self.resultText = nil;
    [super dealloc];
}

@end

The if else cgRect dimensions worked fine previously, however I have probably accidently deleted something or put a comma somewhere that has knocked into this error and causes the application to pause on load. Below is the error it throughs back:

2013-04-03 10:57:35.928 P&H Scanner[269:907] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ReaderSampleViewController 0x21073bc0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'
*** First throw call stack:
(0x3346e3e7 0x3b169963 0x3346e0d5 0x33cdc7d9 0x33cd8543 0x333f48a5 0x35419e7d 0x354196ff 0x35312079 0x3529c451 0x352dcd59 0x35327ef7 0xb6cb 0x352ddaa1 0x352dd625 0x352d5833 0x3527dd1f 0x3527d7ad 0x3527d1ef 0x36f955f7 0x36f95227 0x334433e7 0x3344338b 0x3344220f 0x333b523d 0x333b50c9 0x352d446d 0x352d12b9 0xb605 0x3b596b20)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

Apologies, am relatively new to app development so trying to get head round the different errors and struggling. Any advice would be great


Solution

  • Lets have a look at the Logfile: ("How to read a Logfile:")

    2013-04-03 10:57:35.928 P&H Scanner[269:907] * **Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ReaderSampleViewController 0x21073bc0 setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'

    So, you see that the termination is happening because your Declaration of the ReaderSample View Controller is not correct. To determine what exactly is not correct we can have a look at this part:

    setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.

    So you are setting a Value for the Controller (in your Code it is ZBarReaderDelegate) what seems to be causing the error.

    Because:this class is not key value coding-compliant for the key delegate

    Hope that helps you, Sincerely Maurice Arikoglu