iOS无法使用UIDocumentInteractionController与Whatsapp共享视频

问题描述 投票:2回答:3

它成功地重定向到Whatsapp应用程序。没有预览框架,当点击发送时,弹出错误消息“此视频无法发送。请选择其他视频。

这是我的代码。

- (void)shareVideo {
NSLog(@"[WhatsAppShare] sharing video");
//NSString *nativePath = [[NSString alloc] initWithCString:path encoding:NSASCIIStringEncoding];
NSString *nativePath=[[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];

// Save video to path in documents directory
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wam"];

if([[NSFileManager defaultManager] fileExistsAtPath:savePath]){
    if([[NSFileManager defaultManager] removeItemAtPath:savePath error:nil]){
        [self shareVideoAtNativePath:nativePath SavePath:savePath];
    }
} else {
    [self shareVideoAtNativePath:nativePath SavePath:savePath];
}}

- (void)shareVideoAtNativePath:(NSString*)nativePath SavePath:(NSString*)savePath{
NSError*error;
BOOL isSuccess=[[NSFileManager defaultManager] copyItemAtPath:nativePath toPath:savePath error:&error];
if(isSuccess){
    // Create interaction controller
    self.documentInteractionController          = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    self.documentInteractionController.UTI      = @"net.whatsapp.movie";
    self.documentInteractionController.delegate = self;

    [self.documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 1, 1)
                                                           inView:[self view]
                                                         animated:YES];
} else{
    NSLog(@"error %@", error);
}
}
ios video whatsapp
3个回答
1
投票

我们观察到了完全相同的问题。在最近更新WhatsApp之前,一切正常。这可能是WhatsApp方面的一个错误。

以下是此问题的解决方法:

  • 不要使用wam文件,直接使用mp4文件。所以在你的情况下,只需打电话 [self shareVideoAtNativePath:nativePath SavePath:nativePath];
  • 将UTI更改为公共Mpeg4: self.documentInteractionController.UTI = @"public.mpeg-4";

这似乎解决了我们的问题。但是,有一个缺点是,共享对话框现在包含许多可以打开mp4文件的其他应用程序/服务。


1
投票

我们遇到了完全相同的问题。

官方的.wam格式仅在共享对话框中显示WhatsApp,但无法转发视频。

使用.m4v格式对我们有用。还有一些选项与WhatsApp一起显示(Open in WhatsApp是我们想要的选项)。在将用户发送到共享对话框之前,我们正在显示警告“请在下一个屏幕上选择Whatsapp”。

文件格式:m4v

使用net.whatsapp.movie

请参考下面的工作代码:

 UIDocumentInteractionController *documentInteractionController;
    -----
    -----
 - (void)shareVideoViaWhatsApp:(NSURL*)url{    
        // Creating temp video to share specifically on whatsapp.   
        NSString *cachesFolder = [NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat:@"video.m4v"]];
        NSURL *file = [NSURL fileURLWithPath:cachesFolder];
        [[NSData dataWithContentsOfURL:url] writeToURL:file options:NSDataWritingAtomic error:nil];

        documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL: file ];
        documentInteractionController.UTI = @"net.whatsapp.movie";

        documentInteractionController.delegate = self;
        [documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
 }

0
投票
// In code Use share GIF and Video for WhatsApp....

  NSString    *savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wam"];
savePath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:_videourl];
_documentInteractionController.UTI = @"net.whatsapp.movie";
_documentInteractionController.delegate = (id)self;
[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
© www.soinside.com 2019 - 2024. All rights reserved.