1

您好,我的项目遇到了一个小问题。我制作了一个 QR e 阅读器,它可以扫描条形码,然后在我的网站上搜索结果,但是在扫描 6 次后,我的应用程序就崩溃了,我希望有人能帮助我。

我是 Objective-C 和 iPhone SDK 的新手,但我真的需要这个项目,谢谢。

AppDelegate.h

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;

@end

视图控制器.h

#import <UIKit/UIKit.h>
#import "ZBarSDK.h"

@interface ViewController : UIViewController<ZBarReaderDelegate> {
    IBOutlet UIWebView *myWeb;
    IBOutlet UITextView *resultTextView;
}

- (IBAction)startScanning:(id)sender;

@end

视图控制器.m

#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

#pragma mark - ViewController's LifeCycle methods

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - Button click method

- (IBAction)startScanning:(id)sender {

    ZBarReaderViewController *codeReader = [ZBarReaderViewController new];
    codeReader.readerDelegate=self;
    codeReader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = codeReader.scanner;
    [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];

    [self presentViewController:codeReader animated:YES completion:nil];
}

#pragma mark - ZBar's Delegate method

- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    //  get the decode results
    id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];

    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // just grab the first barcode
        break;

    NSString *myString = [NSString stringWithFormat:@"http://www.northland-cc.com/%@", symbol.data];
    NSURL *url = [NSURL URLWithString:myString];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [myWeb loadRequest:requestObj];

    // dismiss the controller
    [reader dismissViewControllerAnimated:YES completion:nil];
}

@end
4

0 回答 0