Share video on whatsapp - objective c

六月ゝ 毕业季﹏ 提交于 2019-12-13 02:56:18

问题


On iOS 7.1.1, I can share image by this code on 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];

}

But I want to share video too, I follow tutorial on Wahtsapp tutorial

But How can be the code of video path ?

I mean, What is the alternative object of UIImage object to display video ?

Also, can I share "Link" ?

Thank you,


回答1:


It took me a while, but I put the pieces together

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

This is only to answer your main question: Share video on whatsapp



来源:https://stackoverflow.com/questions/24161321/share-video-on-whatsapp-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!