2013-10-16 20 views
0

我試圖用看起來很標準的方式,使用MFMailComposeViewController將圖庫中的視頻附加到電子郵件中。將M4V視頻連接到電子郵件

使用GPUImage框架以m4v格式錄製視頻,並通過自定義選取器選擇該視頻。

選擇器返回給我一個ALAsset,我從中檢索到一個URL(我已經將它發佈到MPMoviePlayerViewController中,它存在並且播放正常)。

當電子郵件啓動預覽時,它會有一個視頻圖標,它認爲它已附加視頻。

當我發送到一個電子郵件地址,電子郵件根本沒有任何附件。你能幫我看看下面的代碼有什麼問題嗎?

MFMailComposeViewController *mailpicker = [[MFMailComposeViewController alloc] init] ; 
    mailpicker.mailComposeDelegate = self; 
    mailpicker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal ; 
    [mailpicker setSubject:@"Test email!"]; 
    NSData *movieData = [NSData dataWithContentsOfURL:[[asset defaultRepresentation] url]]; 

    NSLog(@"%@", [[asset defaultRepresentation] url]); 

    //I have tried all of the following; 
    [mailpicker addAttachmentData:movieData mimeType:@"video/x-m4v" fileName:@"Video.m4v"]; 
    //[mailpicker addAttachmentData:movieData mimeType:@"application/m4v" fileName:@"Video.m4v"]; 
    //[mailpicker addAttachmentData:movieData mimeType:@"video/m4v" fileName:@"Video.m4v"]; 

    NSString *emailBody = @"Hey!"; 
    [mailpicker setMessageBody:emailBody isHTML:YES]; 
    [self presentModalViewController:mailpicker animated:YES]; 

感謝

回答

0

明白了,我沒有正確讀取文件。

我必須使用asset librarys assetForURL來獲取視頻數據。

對於其他人,請看看這個;

[assetLibrary assetForURL:YOURURL resultBlock:^(ALAsset *asset) // substitute YOURURL with your url of video 

但要小心,您可能需要壓縮/縮小視頻。