肯定有!
在您的 .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];
}
}
编辑:请注意,这是一个非常基本的示例,它不处理诸如用户选择视频而不是图像之类的事件...