我试图通过UIActivityViewController将视频发布到Facebook,vimeo等等。我使用的是iOS7。我听说它可能在iOS7中出现但由于某些原因我无法让它工作。
我的代码是:
NSString *shareString = @"My Personal Flick";
NSURL *url = _URL;
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, anAsset, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:activityViewController animated:YES completion:nil];
有人可以向我解释我哪里出错吗?
只是为了理解我有一个打开UIImagePickerViewController的按钮,我可以选择一个视频而不是将视频保存为_URL - 这是我从中获取_URL。
------CODE FOR CREATING _URL OF VIDEO FILE-----------
- (IBAction)chooseImage:(id)sender {
NSLog(@"Chose Image.");
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
_imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo)
{
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *_URL=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"%@",moviePath);
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
答案 0 :(得分:2)
你不需要资产。电影就像任何其他文件类型的附件一样,你只需要网址。执行以下操作:
你的.h文件中的:
@property (nonatomic, retain) NSURL *fileURL;
你的.m文件中的: 而不是
NSURL *_URL=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
使用
self.fileURL = (NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
而不是
NSURL *url = _URL;
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, anAsset, nil];
只需使用:
NSArray *activityItems = [NSArray arrayWithObjects:shareString, self.fileURL, nil];