如何在 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];
我的错误在哪里?
参考文献: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];
这里是 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)
}
我想在 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];
我的错误在哪里?
参考文献: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];
这里是 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)
}