首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS无法使用UIDocumentInteractionController将视频分享给Whatsapp

iOS无法使用UIDocumentInteractionController将视频分享给Whatsapp
EN

Stack Overflow用户
提问于 2015-10-29 04:48:46
回答 3查看 2K关注 0票数 2

它成功地重定向到Whatsapp app.There是没有预览帧,当点击发送时,会弹出一个错误消息“无法发送此视频。请选择另一个视频。”

这是我的密码。

代码语言:javascript
复制
- (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);
}
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-10-30 13:12:08

我们观察到了同样的问题。直到WhatsApp最近的一次更新,一切都在运转。这可能是WhatsApp端的一个bug。

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

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

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

票数 1
EN

Stack Overflow用户

发布于 2016-02-18 08:42:24

我们也面临过同样的问题。

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

使用.m4v格式对我们是有效的。除了WhatsApp之外,还会显示更多的选项(WhatsApp是我们想要的选项)。在将用户发送到共享对话框之前,我们正在显示一个警告,上面写着“请选择下一个屏幕上的Whatsapp”。

m4v文件格式:

net.whatsapp.movie UTI:

请参阅以下工作守则:

代码语言:javascript
复制
 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];
 }
票数 1
EN

Stack Overflow用户

发布于 2018-09-10 05:49:40

代码语言:javascript
复制
// 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];
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33406138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档