1

我想知道是否有人可以告诉我如何录制视频并将其作为附件添加到 IOS 中的邮件作曲家。越具体越好。谢谢。

4

2 回答 2

3

检查此线程以编程方式捕获视频 有关如何在 iOs 4 中录制视频的基本描述

查看有关 iOS 邮件编写器的本教程 http://www.iostipsandtricks.com/using-apples-mail-composer/

Mail Composer 仅支持图片作为直接附件,其他格式需要添加为 nsdata

在目标 c 中将文件作为附件发送

PS:如果你在没有谷歌搜索的情况下提问,人们可能会否决它。

于 2012-10-22T08:13:14.530 回答
1

.h file

#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 file

- (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.");
    }
}
于 2012-12-22T10:48:09.413 回答