我想拍摄一段视频,之后在一些社交网站和电子邮件上分享,所以我已经拍摄了视频并将其保存到相册中,现在我不知道如何分享拍摄/保存的视频请提出建议为此,这是我的捕获视频存储代码..: -
- (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];
}
}
更新
我已尝试使用此代码生成用于分享视频的小网址,但它无法正常工作:(
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];
在这里,我将能够将视频存储在照片库和文档目录中,现在我想分享它,以便如何做到这一点?请帮忙!
答案 0 :(得分:0)
对于Facebook,正如路易斯在their answer here中所建议的那样:
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];
}