Reputation: 39
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?
Upvotes: 2
Views: 3757
Reputation: 7373
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)
}
Upvotes: 2
Reputation: 4163
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];
Upvotes: 0