我的要求是編寫一個可自動捕捉相機圖片的示例IOS應用程序。使用各種SO環節提供我做執行下面的代碼 -在IOS中自動捕捉圖片
我CameraViewController.h類的定義如下:
@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *ImageView;
@end
而且CameraViewController.m具有下面的代碼:
-(void)viewDidAppear:(BOOL)animated
{
NSLog(@"Setting the background now");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
picker.showsCameraControls = NO;
picker.navigationBarHidden = NO;
picker.toolbarHidden = NO;
[self presentViewController:picker animated:YES completion:NULL];
NSLog(@"Taking the picture now");
[picker takePicture];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"Entered the case of finishing pictures");
}
- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker
{
NSLog(@"Entered the case of cancel");
}
上面的代碼所做的是成功啓動相機應用程序,但我不確定如果takePicture API能夠成功點擊圖片。我在Ipad內的照片應用程序中看不到任何保存的照片,因此我認爲該照片未被點擊。 是否有人可以告訴我,如果我上面的代碼是正確的還是什麼,我需要做的,自動點擊捕捉按鈕,進入相機控件顯示
今天我做了更多的閱讀。我的要求是在顯示相機預覽後自動點擊圖片(用戶不應手動點擊相機應用程序上的按鈕)。我的假設是,takePicture API將?在我的情況下,didFinishPickingMediaWithInfo將無法正常工作,因爲用戶無法手動點擊或選擇「使用照片」選項 – sim
Apple文檔要求在編程調用'takePicture'時不顯示圖像選擇器控件。看到我上面的編輯。 – GoZoner
好吧我沒有將圖像選取器控件添加到否,我用最新的代碼編輯了我的原始問題,但它仍然沒有輸入didFinishPickingMediaWithInfo函數。我懷疑是不是實際上點擊圖片?我還能怎樣才能進入didFinishPickingMediaWithInfo API? – sim