1

こんにちは、私のプロジェクトで少し問題が発生しています。バーコードをスキャンして Web サイトで結果を検索する 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

ViewController.h

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

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

- (IBAction)startScanning:(id)sender;

@end

ViewController.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