0

I am trying to upload a video to Whatsapp with an ALAsset URL, but it is loading the video when I share it using UIActivityViewController

ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];

[assetLibrary assetForURL:self.videoURL resultBlock:^(ALAsset *asset) {
    NSArray *objectsToShare =  @[asset.defaultRepresentation.url];
    FrodoInstagramActivity *instagramActivity = [[FrodoInstagramActivity alloc] init];

    UIActivityViewController *activityVC = [[UIActivityViewController alloc] 
        initWithActivityItems:objectsToShare applicationActivities:@[instagramActivity]];
    [self presentViewController:activityVC animated:YES completion:nil];
} failureBlock:nil];
Keale
  • 3,924
  • 3
  • 29
  • 46
Akanksha Sharma
  • 131
  • 1
  • 10

2 Answers2

1

Try this noh, "Movie" Your video which saved to local directory from video asset.

    NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wam"];

savePath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];


    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.UTI = @"net.whatsapp.movie";
    _documentInteractionController.delegate = (id)self;

    [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];

Save your asset locally, and get the local URL. Pass that URL path on the above code. Let's see.

Dont create each file locally for each video, just use the same file name for all videos and replace videos. And delete the video from local, after successfully uploaded. This might help.

Alvin Varghese
  • 842
  • 10
  • 33
  • I have already tried but creating a temp copy in case of large files can be an issue. Thanks anyway – Akanksha Sharma Oct 05 '15 at 10:30
  • WhatsApp is not loading video with asset url. Every other platform is doing. Still figuring out the actual solution to this problem. For now created a custom activity of whatsapp – Akanksha Sharma Oct 05 '15 at 10:37
  • Did you try this _documentInteractionController code ? – Alvin Varghese Oct 05 '15 at 10:39
  • Yes done that. It is working but the only issue is of large files – Akanksha Sharma Oct 06 '15 at 10:51
  • As we could see that, we cant directly upload videos to whats app using activityController, we have to use _documentInteractionController. For that we need files which are saved in document directory. Try to save the video to directory using some background process, thats the best way. We dont have any other workaround – Alvin Varghese Oct 06 '15 at 11:41
0

I have also face this problem with sharing the link on whatsapp.

In whatsapp sharing was restrit to number of characters.

Please share url and text with maximum 150 characters.

then say what happen.

happy coding :)

Shubham Narang
  • 514
  • 2
  • 14
  • No, the URL is not more than 150 characters. It is assets-library://asset/asset.mp4?id=004BB7E9-6F9F-4C3A-8FAD-CAC26952708C&ext=mp4 – Akanksha Sharma Oct 06 '15 at 10:50