Cordova iOS 6.1.0 如何在 WKwebview 的外部屏幕上显示图像 [英] Cordova iOS 6.1.0 How to display images on external screen in WKwebview

查看:58
本文介绍了Cordova iOS 6.1.0 如何在 WKwebview 的外部屏幕上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用此插件的 Cordova 应用程序 (cordova-plugin-wkwebview-external-screen) 通过 Airplay/HDMI 适配器(类似于 Apple 的 Keynote)在外部屏幕上全屏显示图像/媒体.

使用 UIwebview 一切顺利,但我无法使用 WKwebview 在外部屏幕上显示媒体.我现在使用 Cordova iOS 6.1.1 (CLI 10.0).

我正在使用 window.WkWebView.convertFilePath() 在我的主(控制)屏幕上显示媒体,但是转换后的文件 url 和file://..." url (cordova.file.dataDirectory + 'image.jpg') 在外部屏幕上都不起作用.

附加信息:

  • 我的外部屏幕是通过 ExternalScreen.loadHTML('secondary.html'); 启动的.,但 Cordova 在外部屏幕的窗口中似乎不可用(即使在 secondary.html 中包含了cordova.js).
  • 我的白名单"元数据在我的 index.html(控制)和 secondary.html(显示)文档中是相同的.

如何获取将显示在我的第二个(外部)屏幕上的图片网址?

更新:我已经更新了 plugin 的 getWebView 功能,添加了 allowFileAccessFromFileURLsallowUniversalAccessFromFileURLsallowsInlineMediaPlaybackmediaTypesRequiringUserActionForPlayback 配置:

- (WKWebView*)getWebView {如果(!self.externalWebView){UIScreen* externalScreen = [[UIScreen 屏幕] objectAtIndex: 1];CGRect screenBounds = externalScreen.bounds;self.externalWebView = [[WKWebView alloc] initWithFrame: screenBounds 配置:[[WKWebViewConfiguration alloc] init]];//我加了这四个配置...[self.externalWebView.configuration.preferences setValue:@YES forKey:@allowFileAccessFromFileURLs"];[self.externalWebView.configuration setValue:@YES forKey:@allowUniversalAccessFromFileURLs"];self.externalWebView.configuration.allowsInlineMediaPlayback = TRUE;self.externalWebView.configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;self.externalWindow = [[UIWindow alloc] initWithFrame: screenBounds];self.externalWindow.screen = externalScreen;self.externalWindow.clipsToBounds = YES;[self.externalWindow addSubview:self.externalWebView];[self.externalWindow makeKeyAndVisible];self.externalWindow.hidden = NO;}返回 self.externalWebView;}

不幸的是,这些更改似乎不会影响externalView.我暂时使用此插件作为解决方法(cordova-plugin-wkwebview-sandbox-webserver),但即使如此,我也无法让 HTML5 视频自动播放 - 所以我怀疑我是否将配置设置放在正确的位置?

解决方案

问题是这个插件没有更新.从我在插件中看到的内容来看,它正在尝试使用 file://进行加载,但现在已经无法正常工作了.

 NSString* a = @file://";baseURLAddress = [a stringByAppendingString:baseURLAddress];

您可以尝试将首选项 allowFileAccessFromFileURLsallowUniversalAccessFromFileURLs 添加到此插件在 getWebView 方法中创建的 WKWebViewhref="https://github.com/josiaho/cordova-plugin-wkwebview-external-screen/blob/master/src/ios/WKWebViewExternalScreen.m" rel="nofollow noreferrer">这个文件

您可以基于 这个插件,代码参考

 [wkWebView.configuration.preferences setValue:@(_allowFileAccessFromFileURLs) forKey:@allowFileAccessFromFileURLs"];

虽然这不是一个直接的答案,但克隆 cordova-plugin-wkwebview-external-screen 并添加这些首选项是您最好的选择.

I have a Cordova app that uses this plugin (cordova-plugin-wkwebview-external-screen) to display images/media full screen on an external screen via Airplay/HDMI adapter (similar to Apple’s Keynote).

All worked smoothly with UIwebview, but I’m having trouble displaying media on my external screen with WKwebview. I’m now using Cordova iOS 6.1.1 (CLI 10.0).

I’m using window.WkWebView.convertFilePath() to display media on my primary (control) screen, but neither the converted file url nor the "file://..." url (cordova.file.dataDirectory + ‘image.jpg’) work in the external screen.

Additional info:

  • My external screen is launched via ExternalScreen.loadHTML('secondary.html'); , but Cordova does not appear to be available in the window of the external screen (even when cordova.js is included in secondary.html).
  • My "whitelist" meta data is the same in both my index.html (control) and secondary.html (display) documents.

How do I get image URL’s that’ll display on my second (external) screen?

UPDATE: I've updated the getWebView function of the plugin adding allowFileAccessFromFileURLs, allowUniversalAccessFromFileURLs, allowsInlineMediaPlayback, and mediaTypesRequiringUserActionForPlayback configurations:

- (WKWebView*)getWebView {
    if (!self.externalWebView) {
        UIScreen* externalScreen = [[UIScreen screens] objectAtIndex: 1];
        CGRect screenBounds = externalScreen.bounds;
        self.externalWebView = [[WKWebView alloc] initWithFrame: screenBounds configuration: [[WKWebViewConfiguration alloc] init]];

        // I added these four configurations...
        [self.externalWebView.configuration.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"];
        [self.externalWebView.configuration setValue:@YES forKey:@"allowUniversalAccessFromFileURLs"];
        self.externalWebView.configuration.allowsInlineMediaPlayback = TRUE;
        self.externalWebView.configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;

        self.externalWindow = [[UIWindow alloc] initWithFrame: screenBounds];
        self.externalWindow.screen = externalScreen;
        self.externalWindow.clipsToBounds = YES;
        [self.externalWindow addSubview:self.externalWebView];
        [self.externalWindow makeKeyAndVisible];
        self.externalWindow.hidden = NO;
    }
    return self.externalWebView;
}

Unfortunately, these changes do not seem to impact the externalView. I'm temporarily using this plugin as a workaround (cordova-plugin-wkwebview-sandbox-webserver), but even with that I can't get HTML5 videos to autoplay - so I'm questioning whether I'm even putting the configuration settings in the right place?

解决方案

The issue is that this plugin has not been updated. From what I can see in the plugin, it is trying to load using file:// which is not working anymore out of the box.

    NSString* a = @"file://";
    baseURLAddress = [a stringByAppendingString:baseURLAddress];

You could try to add the preferences allowFileAccessFromFileURLs and allowUniversalAccessFromFileURLs to the WKWebView that is created by this plugin in the getWebView method in this file

You can base your work on this plugin, code for reference

 [wkWebView.configuration.preferences setValue:@(_allowFileAccessFromFileURLs) forKey:@"allowFileAccessFromFileURLs"];

While this is not a straight answer, cloning cordova-plugin-wkwebview-external-screen and adding theses preferences is your best shot.

这篇关于Cordova iOS 6.1.0 如何在 WKwebview 的外部屏幕上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆