-2

我想拍摄一段视频,然后在一些社交网站和电子邮件上分享,所以我已经拍摄了视频并将其保存到相册中,现在我不知道如何分享拍摄/保存的视频,请为此提出建议,这是我用于捕获视频存储的代码..:-

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
    // NSLog(@"dictionary info %@", info);

    if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath))
    {
        // Copy it to the camera roll.

        UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath);

        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

        NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];

        vidPath = [documentsDirectory stringByAppendingFormat:@"/vid1.mp4"];
        [vidPath retain];

        BOOL success = [videoData writeToFile:vidPath atomically:NO];

        NSLog(@"Written file on path success? , %@\n", (success ? @"YES" : @"NO"));

        [picker dismissModalViewControllerAnimated:YES];
    }
}

更新

我已经尝试使用此代码生成用于共享视频的小 url,但它不起作用:(

NSString *apiEndpoint = [NSString stringWithFormat:@"http://tinyurl.com/api-create.php?url=%@",vidPath];
[apiEndpoint retain];

shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
                                    encoding:NSASCIIStringEncoding
                                       error:nil];
[shortURL retain];

在这里,我可以将视频存储在照片库和文档目录中,现在我想分享它,那该怎么做呢?请帮忙!

4

1 回答 1

0

对于 Facebook,正如 Luis 在此处的回答中所建议的:

NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/videos"];

NSURL *videoPathURL = [[NSURL alloc]initFileURLWithPath:videoPath isDirectory:NO];
NSData *videoData = [NSData dataWithContentsOfFile:videoPath];

NSString *status = @"One step closer.";
NSDictionary *params = @{@"title":status, @"description":status};

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodPOST 
                                                  URL:url 
                                           parameters:params];

[request addMultipartData:videoData
                 withName:@"source"
                     type:@"video/quicktime" 
                 filename:[videoPathURL absoluteString]];

电子邮件

-(IBAction)sendmailPress:(id)sender
{

MFMailComposeViewController* Apicker = [[MFMailComposeViewController alloc] init];
    if (Apicker != nil)
    {

        [Apicker setSubject:@""];

        [Apicker setMessageBody:@" " isHTML:NO];


        [Apicker setToRecipients:toRecipients];

        Apicker.mailComposeDelegate = self;

        NSData *mym=[NSData dataWithContentsOfFile:VideoPath];

       NSLog(@"%@",mym);
        [Apicker addAttachmentData:mym mimeType:@".Extension" fileName:videoname];
[self presentModalViewController:Apicker animated:YES];
        [Apicker release];
}

在此处输入图像描述

在此处输入图像描述

于 2013-10-22T04:40:11.553 回答