私が開発しているiPhoneアプリの中には、iPhone3.0のアプリ内メールを使用して画像を送信できる部分があります。カメラロールから画像を選択することは完全に機能しますが、カメラから電子メールに移動しようとすると(つまり、UIImagePickerControllerからMFMailComposeViewControllerに)、アプリケーションがクラッシュします。
これはカメラを実行するためのコードです:
- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate, UINavigationControllerDelegate>)delegateObject
{
if ( (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) || (delegateObject == nil) || (controller == nil))
return NO;
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = delegateObject;
picker.allowsImageEditing = NO;
[controller presentModalViewController:picker animated:YES];
return YES;
}
そして、これはカメラで仕上げるためのコードです:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSLog(@"Called finish picking");
self.imageForSending = theImage;
// NSData *imageData = UIImageJPEGRepresentation(image, 1);
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] recoverNavigationBar];
[self performSelector:@selector(sendEmail) withObject:nil afterDelay:0.45];
[picker release];
}
そして、これはメールを送信するためのコードです:
- (void) sendEmail {
[(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] hideNavigationBar];
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"שגיאה", @"") message:NSLocalizedString(@"לא ניתן לשלוח מייל ממכשיר זה", @"")
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
else
{
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[[controller navigationBar] setTintColor:[UIColor colorWithRed:120.0/255.0 green:0 blue:0 alpha:1.0]];
NSData *imageData = UIImageJPEGRepresentation(imageForSending, 1);
[controller addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"storyImage.jpg"];
[controller setSubject:@""];
[controller setToRecipients:[NSArray arrayWithObject:@""]];
[self presentModalViewController:controller animated:YES];
[controller release];
}
}
メールアドレスと件名は関連性が低いので消去しました。
クラッシュは、電子メールのpresentModalViewControllerで発生します。繰り返しますが、この正確なコードは、カメラロールから画像を選択するときに完全に機能します...
ヘルプ ?私はしばらくの間これと戦ってきました、そして本当にいくつかの新しい入力を使うことができました。ありがとう!