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



我想在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/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];

最新更新