現在のアプリケーションでは、ユーザーがオンラインのイメージ サービスにイメージを送信できるようにしています。ユーザーは、フォト アルバムから選択するか、カメラで写真を撮ることができます。
しかし、私には問題があります。使用されているデバイスにカメラがなく、ユーザーが写真を撮ることを選択した場合、アプリケーションはクラッシュします。デバイスが cameraDevice を使用できるかどうかを判断できる必要があります。
以下は、ユーザーがさまざまなオプションを選択できるようにする UIActionSheet を表示するための現在のコードです。
#pragma mark -
#pragma mark UIImagePickerController
- (IBAction)ImagePicker {
UIActionSheet *sheet = [[UIActionSheet alloc]
initWithTitle:@"" delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Choose An Existing Photo", @"Take A Photo", nil];
sheet.actionSheetStyle = UIActionSheetStyleDefault;
[sheet showInView:self.view];
[sheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
//Okay the UIImagePickerControllerSourceTypeSavedPhotosAlbum displays the
NSLog(@"Album");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
} else if (buttonIndex == 1) {
NSLog(@"Camera");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
前もって感謝します!