मेरे पास कैमरा पूर्वावलोकन विंडो है जो 90% समय पर अच्छी तरह से काम कर रही है। कभी-कभी, जब मेरे ऐप पर वापस आ जाता है तो पृष्ठभूमि में होता है, तो पूर्वावलोकन प्रदर्शित नहीं होगा। इस कोड को मैं फोन जब दृश्य लोड है:पृष्ठभूमि से लौटने पर AVCaptureSession विफल रहता है
- (void) startCamera {
session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetPhoto;
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = _cameraView.bounds;
[_cameraView.layer addSublayer:captureVideoPreviewLayer];
captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
captureVideoPreviewLayer.position=CGPointMake(CGRectGetMidX(_cameraView.bounds), 160);
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
NSLog(@"ERROR: %@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Important!"
message:@"Unable to find a camera."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert autorelease];
}
[session addInput:input];
stillImage = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG , AVVideoCodecKey, nil];
[stillImage setOutputSettings:outputSettings];
[session addOutput:stillImage];
[session startRunning];
}
यदि ऐसा होता है, मैं फिर से वापस मेरी प्राथमिकताओं दृश्य में स्विच कर सकते हैं और अच्छी तरह से और अल है, लेकिन यह एक कष्टप्रद बग मैं को मारने के लिए करना चाहते हैं है। पूर्वावलोकन विंडो मेरी स्टोरीबोर्ड में एक UIView है।
धन्यवाद, मैं ऐसा और कुछ ही घंटों :) – mrEmpty
शानदार समाधान के लिए यह परीक्षण करेंगे ....... –
प्रतीक्षा - नहीं यह मामला है कि 'viewWillAppear' /' Disappear' केवल कहलाते हैं क्योंकि दृश्य आपके ऐप में घूमता है: उन्हें ऐप के अंदर और बाहर जाने के रूप में नहीं कहा जाता है? 'UIAplplicationWillResignActiveNotification' के लिए पंजीकरण करना आवश्यक नहीं होगा और इसका उपयोग करें? [क्यूए उस के उदाहरण के साथ] (http://stackoverflow.com/a/22868754/294884) – Fattie