AVCaptureSession addInput:不使用iOS7

AVCaptureSession addInput:不使用iOS7,ios,ios7,avcapturesession,Ios,Ios7,Avcapturesession,我有一个应用程序可以与以前的iOS版本正常工作,但后来我尝试在带有iOS7的设备上运行它,应用程序崩溃了。我尝试使用Xcode 5进行构建,这是Apple iOS7 GM SDK推荐的升级现有应用程序的方法,但问题没有解决。我试图研究苹果公司的AVCaptureSession文档,但也没有发现任何东西 我的代码简单而标准 -(void)addVideoInput { AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDevic

我有一个应用程序可以与以前的iOS版本正常工作,但后来我尝试在带有iOS7的设备上运行它,应用程序崩溃了。我尝试使用Xcode 5进行构建,这是Apple iOS7 GM SDK推荐的升级现有应用程序的方法,但问题没有解决。我试图研究苹果公司的
AVCaptureSession
文档,但也没有发现任何东西

我的代码简单而标准

-(void)addVideoInput { 
    AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (videoDevice) {
        NSError *error;
        self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
        if ([self.captureSession canAddInput:self.videoInput]) {
            [self.captureSession addInput:self.videoInput];
        }
    }
}
应用程序在我的函数中崩溃,出现下一个Stacktrace:

0 libobjc.A.dylib 0x395adb26 objc_msgSend + 5
1 AVFoundation 0x2e33a991 <redacted> + 348
2 AVFoundation 0x2e33aca1 <redacted> + 112
3 AVFoundation 0x2e33c4d1 <redacted> + 316
4 AVFoundation 0x2e33560f <redacted> + 354
5 AVFoundation 0x2e339bf1 <redacted> + 1436
6 Foundation 0x2fdbed31 <redacted> + 272
7 Foundation 0x2fdbe9d5 <redacted> + 344
8 Foundation 0x2fdaafed <redacted> + 88
9 AVFoundation 0x2e327483 <redacted> + 94
10 AVFoundation 0x2e33c505 <redacted> + 368
11 AVFoundation 0x2e3362c7 <redacted> + 906
12 myApp 0x00156159 -[CaptureManagerUniversal addVideoInput] + 540
13 myApp 0x00154cdf -[CaptureManagerUniversal init] + 2178
14 myApp 0x00077575 -[ViewFinderViewController didAppearActions] + 312
15 myApp 0x00077b11 -[ViewFinderViewController viewDidAppear:] + 128
16 UIKit 0x3199d43b <redacted> + 410
17 UIKit 0x3199d8bd <redacted> + 264
18 UIKit 0x31a4a4cb <redacted> + 870
19 UIKit 0x31a4a15b <redacted> + 274
20 UIKit 0x319bb417 <redacted> + 178
21 UIKit 0x319bb32f <redacted> + 70
22 QuartzCore 0x31613d99 <redacted> + 232
23 libdispatch.dylib 0x39ab1d67 <redacted> + 22
24 libdispatch.dylib 0x39ab87c1 <redacted> + 268
25 CoreFoundation 0x2f47a811 <redacted> + 8
26 CoreFoundation 0x2f4790e5 <redacted> + 1300
27 CoreFoundation 0x2f3e3cd7 CFRunLoopRunSpecific + 522
28 CoreFoundation 0x2f3e3abb CFRunLoopRunInMode + 106
29 GraphicsServices 0x33e602db GSEventRunModal + 138
30 UIKit 0x319e8121 UIApplicationMain + 1136
31 myApp 0x00097a9d main + 11 6
0 libobjc.A.dylib 0x395adb26 objc_msgSend+5
1 AV2E33A991+348
2 AV2E33ACA1+112
3 AV2E33C4D1+316
4 AV2E33560F+354
5 AV2E339BF1+1436
6基金会0x2FDBED331 + 272
7基金会0x2FDBE9D5+ 344
8基金会0x2FDAAFED + 88
9 AV2E327483+94
10 AV2E33C505+368
11 AV2E3362C7+906
12 myApp 0x00156159-[CaptureManagerInterversal addVideoInput]+540
13 myApp 0x00154cdf-[CaptureManageRunInterversal init]+2178
14 myApp 0x00077575-[ViewFinderViewController显示界面]+312
15 myApp 0x00077b11-[ViewFinderViewController ViewDidDisplay:][128
16 UIKit 0x3199d43b+410
17 UIKit 0x3199d8bd+264
18 UIKit 0x31a4a4cb+870
19 UIKit 0x31a4a15b+274
20 UIKit 0x319bb417+178
21 UIKit 0x319bb32f+70
22夸脱芯0x31613d99+232
23 libdispatch.dylib 0x39ab1d67+22
24 libdispatch.dylib 0x39ab87c1+268
25芯基础0x2f47a811+8
26芯基础0x2f4790e5+1300
27 CoreFoundation 0x2f3e3cd7 CFRunLoopRunSpecific+522
28 CoreFoundation 0x2f3e3abb CFRUNLOOPSRUNINMODE+106
29图形服务0x33e602db GSEventRunModal+138
30 UIKit 0x319e8121 UIApplicationMain+1136
31 myApp 0x00097a9d干管+11 6

我在自定义CaptureManager中添加了
解除锁定
方法:

[self.captureSession removeInput:self.videoInput];
[self.captureSession removeOutput:self.videoOutput];
以前

self.captureSession = nil;
self.videoOutput = nil;
self.videoInput = nil;
而且它对我有效(对于iOS7也是如此)

我现在的
dealloc
方法是:

- (void)dealloc {
    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
    [notificationCenter removeObserver:[self deviceConnectedObserver]];
    [notificationCenter removeObserver:[self deviceDisconnectedObserver]];
    [notificationCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    [self.captureSession stopRunning];
    [self.captureSession removeInput:self.videoInput];
    [self.captureSession removeOutput:self.videoOutput];
    self.captureSession = nil;
    self.videoOutput = nil;
    self.videoInput = nil;
}

可能是您正在释放一个已经释放的对象(隐式地在自动释放池中..等等)。@iPatel您是对的!我使用了用于僵尸的工具,结果是:
向地址为0x1568df30的已解除分配的“CaptureManagerUniversal”对象(僵尸)发送了一条Objective-C消息。
。非常感谢。我认为iOS7与以前的版本有很多不同之处。+1对你来说,你也解决了我的问题。AVCaptureVideoDataOutput有问题。当我取消分配camera类时,我的应用程序在IOS7上崩溃。在得到您的答案后,我还删除了添加到会话中的输入和输出,现在应用程序在所有IOS版本上都运行良好。我很高兴这个解决方案帮助了您:)也解决了我的问题,我完全不知所措:)