繁体   English   中英

如何在iOS的whatsapp上分享视频?

[英]How to share video on whatsapp in iOS?

我想在whatsapp上共享视频,但是我遇到savePath nil错误。

我使用以下代码:

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

我的错误在哪里?

这是Swift版本:

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)

}

参考: 在iOS应用中通过WhatsApp共享图像/文本 // http://www.whatsapp.com/faq/zh/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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM