关于UIApplicationMain错误的SIGABRT

时间:2013-04-03 09:59:37

标签: ios xcode4 sigabrt

我已搜索和搜索,尽管在这个问题上有很多主题,但我找不到任何相关的解决我的问题。如果有人可以请一看:

我正在使用xcode 4.6

我在int retVal

的main.m文件中收到错误
int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

我的ReaderSampleViewController.h文件如下所示:

@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

ReaderSampleViewController.m文件如下所示:

#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

if else cgRect维度之前工作正常,但是我可能会意外删除某些内容或者在某个地方放入一个已经导致此错误的逗号并导致应用程序在加载时暂停。以下是它经历的错误:

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) 
道歉,对应用开发来说相对较新,所以试图了解不同的错误并努力解决。任何建议都会很棒

2 个答案:

答案 0 :(得分:3)

我学到的一个小技巧是在整个应用程序上有一个异常断点,所以每当你得到一个你不认识的错误(比如与UIApplicationMain相关的错误)时,至少你会得到一个粗略的想法代码中断了。这可以为您提供启动所需的线索。

要做到这一点,你需要转到断点导航器(Cmd + 6),按左下角的小加号图标,选择&#34;添加异常断点&#34;最后按完成。

答案 1 :(得分:2)

让我们看一下Logfile: (“如何读取日志文件:”)

  

2013-04-03 10:57:35.928 P&amp; H Scanner [269:907] * **终止app到期   未捕获的异常'NSUnknownKeyException',原因:   '[ReaderSampleViewController 0x21073bc0 setValue:forUndefinedKey:] :   这个类不是密钥代表的密钥值编码兼容。'

因此,您看到终止正在发生,因为您的ReaderSample View Controller声明不正确。 要确定什么完全不正确,我们可以查看此部分:

  

setValue:forUndefinedKey:]:此类不是密钥委托的密钥值编码兼容。

所以你要为Controller设置一个值(在你的代码中它是ZBarReaderDelegate) 似乎导致错误的原因。

因为:此类不符合关键代表的键值编码

希望能帮到你,真诚的Maurice Arikoglu