简体   繁体   English

iPhone SDK录制视频然后通过电子邮件发送

[英]iPhone SDK record video then email it

I was wondering if someone could show me how to record video and add it as attachment to mail composer in IOS. 我想知道是否有人可以告诉我如何录制视频并将其添加为IOS中邮件编辑器的附件。 The more specific the better. 越具体越好。 Thanks. 谢谢。

Check this thread for capturing video programatically Basic description on how to record video in iOs 4 检查此线程以编程方式捕获视频有关如何在iOs中录制视频的基本说明4

Check this tutorial about mail composer for iOS http://www.iostipsandtricks.com/using-apples-mail-composer/ 查看本教程关于iOS的邮件编辑器http://www.iostipsandtricks.com/using-apples-mail-composer/

Mail composer only supports images as direct attachments and other formats are needed to be added as nsdata 邮件编辑器仅支持图像作为直接附件,其他格式需要添加为nsdata

Send a file as attachment in objective c 在目标c中将文件作为附件发送

PS : If you ask questions without googling people will probably down-vote it. PS:如果你在没有谷歌搜索的情况下提出问题,人们可能会对其进行投票。

.h file .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 file .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.");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM