2

I want to share video on whatsapp but I have savePath nil error.

I used this code:

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

Where is my error?

luk2302
  • 55,258
  • 23
  • 97
  • 137
BenAY
  • 39
  • 1
  • 2
  • 7

2 Answers2

2

Here is the Swift version:

func sendVideo(videoName: String, senderView: UIView) {

    let path = NSBundle.mainBundle().pathForResource(videoName, ofType:"m4v")! 
    let fileUrl = NSURL(fileURLWithPath: path)! 

    docController = UIDocumentInteractionController(URL: fileUrl) 
    docController.UTI = "net.whatsapp.movie"
    docController.presentOpenInMenuFromRect(CGRectZero, inView: senderView, animated: true)

}
Swinny89
  • 7,273
  • 3
  • 32
  • 52
  • 1
    I'm not sure why you casted fileUrl as NSURL when it was already an NSURL. You seem to be creating 'data' but not doing anything with it. – Peter Parker Jul 17 '16 at 12:50
0

references: Share image/text through WhatsApp in an iOS app // http://www.whatsapp.com/faq/en/iphone/23559013

//---NEXT LINE OF CODE IS OPTIONAL AND NOT RECOMMENDED, BUT YOU CAN USE IT TO TEST TO SEE IF THEY HAVE THE WHATSAPP INSTALLED
//    if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){
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];
Community
  • 1
  • 1
Janmenjaya
  • 4,149
  • 1
  • 23
  • 43