7

我有一个应用程序可以在以前的 iOS 版本上正常工作,但后来我尝试在装有 iOS7 的设备上运行它,应用程序偶尔崩溃。我尝试使用Apple iOS7 GM SDK推荐的Xcode 5进行构建以升级现有应用程序,但问题没有解决。我试图研究 Apple 文档,但也没有找到任何东西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
4

1 回答 1

10

dealloc我在自定义 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;
}
于 2013-09-17T11:43:37.797 回答