我想拍摄一段视频,然后在一些社交网站和电子邮件上分享,所以我已经拍摄了视频并将其保存到相册中,现在我不知道如何分享拍摄/保存的视频,请为此提出建议,这是我用于捕获视频存储的代码..:-
- (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];
在这里,我可以将视频存储在照片库和文档目录中,现在我想分享它,那该怎么做呢?请帮忙!