Pregunta

I'm trying to post a video to Facebook, vimeo, whatever through UIActivityViewController. I'm using iOS7. I've heard that its possible in iOS7 but for some reason I'm having trouble getting it to work.

My code is:

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];

Can someone please explain to me where I'm going wrong?

Just to understand I have a button that opens UIImagePickerViewController where I can choose a video and than it saves the video as _URL - that's were I'm getting the _URL from.

------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);
¿Fue útil?

Solución

you dont need to an asset. the movie is like any other filetype an attachment and for that you need only the url. do the following:

in your .h file:

@property (nonatomic, retain) NSURL *fileURL;

in your .m file: instead of

NSURL *_URL=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];

use

self.fileURL = (NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];

and instead of

NSURL *url = _URL;
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, anAsset, nil];

simply use:

NSArray *activityItems = [NSArray arrayWithObjects:shareString, self.fileURL, nil];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top