確かにあります!
.h ファイルにこれらのデリゲートを追加し、UIImage
名前付きの selectedImage を宣言します。
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
次に、.m に以下を追加できます。
-(IBAction)openImagePicker:(id)sender
プロセスを開始するボタンへのリンク。
- (IBAction)openImagePicker:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^{
[self openEmail];
}];
}
-(IBAction) openEmail {
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setToRecipients:[NSArray arrayWithObjects:@"TPsecondary_Example@email.com", nil]];
[mailComposer setSubject:@"Learning Trail Submission"];
[mailComposer setMessageBody:emailbody isHTML:NO];
[mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Answer" ofType:@"plist"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[mailComposer addAttachmentData:myData mimeType:@"application/xml" fileName:@"Answer.plist"];
NSData *imageData = UIImageJPEGRepresentation(selectedImage, 1.0);
[mailComposer addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"imageTitle"];
[self presentModalViewController:mailComposer animated:YES];
}
}
編集:これは、ユーザーが画像ではなくビデオを選択するなどのイベントを処理しない非常に基本的な例です...