2015-04-19 45 views
2

是否有可能更新此代碼以在模擬器中運行?現在,我的應用程序工作與崩潰,當它到達代碼中的這一點。是否有我們可以添加的nslog語句來允許我測試此功能?我需要在我的iPad和模擬器上同時進行測試,但是當我達到此代碼時模擬器崩潰。在iOS模擬器中測試iPhone相機?

- (void)snapStillImage //this is being called on did load 
{ 
dispatch_async([self sessionQueue], ^{ 
    // Update the orientation on the still image output video connection before capturing. 
    [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]]; 
    // Flash set to Auto for Still Capture 
    [ViewController5 setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]]; 
    // Capture a still image. 
    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { 
     if (imageDataSampleBuffer) 
     { 
      NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 

      photo.image = [[UIImage alloc] initWithData:imageData]; 
      [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[photo.image CGImage] orientation:(ALAssetOrientation)[photo.image imageOrientation] completionBlock:nil]; 
      [self uploadPhoto]; 
} 
    }]; 
}); 
} 

例如這裏是允許測試UIImage的選擇器,但是我現在用AVCam方法...

-(void)takePhoto { 
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
#if TARGET_IPHONE_SIMULATOR 
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
#else 
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
#endif 
imagePickerController.editing = YES; 
imagePickerController.delegate = (id)self; 

[self presentModalViewController:imagePickerController animated:YES]; 
} 

回答

3

不,你不能在模擬器使用相機。試圖加載相機並且硬件不存在時它會崩潰。您需要使用所有這些功能的設備。如果您只需要相機,iPod touch就是一個很好的解決方案。

+0

希望我還有我的iPod touch ... iPad來拯救。 – zaprogers