我想知道是否有人可以告诉我如何录制视频并将其作为附件添加到IOS中的邮件编辑器。越具体越好。感谢。
答案 0 :(得分:3)
检查此线程以编程方式捕获视频 Basic description on how to record video in iOs 4
查看本教程关于iOS的邮件编辑器 http://www.iostipsandtricks.com/using-apples-mail-composer/
邮件编辑器仅支持图像作为直接附件,其他格式需要添加为nsdata
P.S:如果你在没有谷歌搜索的情况下提出问题,人们可能会对其进行投票。答案 1 :(得分:1)
.h文件
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImagePickerController *imagePicker;
NSURL *videoURL;
}
-(IBAction)submitVideo;
.m文件
- (void)viewDidLoad
{
[super viewDidLoad];
//set image picker
imagePicker = [[UIImagePickerController alloc]init];
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
imagePicker.mediaTypes = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF contains %@)", @"movie"]];
imagePicker.delegate = self;
imagePicker.videoMaximumDuration = 60.0;
imagePicker.allowsEditing = YES;
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
-(IBAction)submitVideo
{
[self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"movie captured %@", info);
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(sendMail) userInfo:nil repeats:NO];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)sendMail
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail addAttachmentData:[NSData dataWithContentsOfURL:videoURL] mimeType:@"video/MOV" fileName:@"Video.MOV"];
[mail setSubject:@"video"];
[mail setMessageBody:@"body" isHTML:YES];
[mail setToRecipients:[NSArray arrayWithObject:@"myemail@jhd.com"]];
[self presentViewController:mail animated:YES completion:nil];
}else {
NSLog(@"Device is unable to send the request in its current state.");
}
}