在whatsapp上分享视频 - 目标c

时间:2014-06-11 11:04:51

标签: ios objective-c video ios7.1 whatsapp

在iOS 7.1.1上,我可以在Whatsapp上通过此代码共享图像..

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){

        UIImage     * iconImage = [UIImage imageNamed:@"image.png"];
        NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

        [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

        self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
        self.docController.UTI = @"net.whatsapp.image";
        self.docController.delegate = self;
        //[self.docController setAnnotation:@{@"WhatsappCaption" : @"https://itunes.apple.com/us/app/epic-ar/id535122470?ls=1&mt=8"}];

        [self.docController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:appDelegate.window.rootViewController.view animated: YES];

}

但我也想分享视频,我按照Wahtsapp tutorial

上的教程

但视频路径代码怎么样?

我的意思是,UIImage对象的替代对象是什么来显示视频?

另外,我可以分享" Link" ?

谢谢,

1 个答案:

答案 0 :(得分:2)

我花了一段时间,但我把各个部分放在一起

参考: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];

这只是回答你的主要问题:在whatsapp上分享视频