小编Boe*_*ger的帖子

iOS正确停止AVCaptureSession

我在iOS 7中测试新的条形码扫描api时出了问题.这个例子(单视图应用程序)工作正常,但我想停止AVCaptureSession并在摄像机识别出EAN代码后显示第一个视图.

[self.captureSession startRunning]; 不起作用.

我如何正确停止AVCaptureSession?

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface ViewController ()  <AVCaptureMetadataOutputObjectsDelegate>

@property (strong) AVCaptureSession *captureSession;

@end

@implementation ViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.captureSession = [[AVCaptureSession alloc] init];
    AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error = nil;
    AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
    if(videoInput)
        [self.captureSession addInput:videoInput];
    else
        NSLog(@"Error: %@", error);

    AVCaptureMetadataOutput *metadataOutput = [[AVCaptureMetadataOutput alloc] init];
    [self.captureSession addOutput:metadataOutput];
    [metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
    [metadataOutput setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code]];

    AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
    previewLayer.frame = self.view.layer.bounds;
    [self.view.layer addSublayer:previewLayer];

    [self.captureSession startRunning]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios ios7

11
推荐指数
1
解决办法
2万
查看次数

以编程方式备份​​完整的iPhone AddressBook

我需要以编程方式备份​​所有记录(数字,名称,图像......)的所有联系人.我读到了关于AddressBook.framework的内容,但有一种简单的方法来备份所有联系人吗?

iphone xcode objective-c ios

1
推荐指数
1
解决办法
1770
查看次数

标签 统计

ios ×2

iphone ×2

objective-c ×2

ios7 ×1

xcode ×1