WKWebview 和 <input type="file"

WKWebview and <input type="file"

我在 iOS 上遇到 WKWebView 的问题。点击元素 <input type="file" accept="image/*"> 后出现带有三个选项的 ActionSheet:Photo LibraryiCloudCancel .

然后,当我点击 图片库 时,ActionSheet 消失,并且 WebView 阻止再次打开 ActionSheet。我卡住了,无法通过 WebView 上传照片。

我在 info.plist 文件中添加了权限(隐私 - 照片库使用说明)。下面是我如何创建 WebView

WKWebViewConfiguration *wkConfiguration = [[WKWebViewConfiguration alloc] init];
wkConfiguration.allowsInlineMediaPlayback = true;
wkConfiguration.mediaPlaybackRequiresUserAction = false;

self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:wkConfiguration];

self.webView.scrollView.bounces = NO;
self.webView.contentScaleFactor = 2.0;
self.webView.exclusiveTouch = YES;
[self.webView.scrollView setDelaysContentTouches:NO];
[self.webView.scrollView setDecelerationRate:UIScrollViewDecelerationRateNormal];

self.webView.UIDelegate = self;
self.webView.navigationDelegate = self;

最糟糕的是,我无法在 input 上捕获点击事件。也许有人有类似的问题?我从 Stack 和 Apple 论坛搜索了其他主题,但都没有帮助。我会很感激你的帮助。

已编辑

正在打印系统日志:

<Error>: -[NETAWDManager reportStats:metricID:] AWDServerConnection newMetricContainerWithIdentifier failed for metric 2686983, server 0x16d62570, not reporting:
<AWDLibnetcoreTCPConnectionReport: 0x16e418a0> {
    cellularFallbackReport =     {
        dataUsageSnapshotsAtNetworkEvents =         (
                        {
                bytesIn = 1999999;
                bytesOut = 1600;
            }
        );
        "fallbackTimer_msecs" = 0;
        fellback = 0;
        networkEvents =         (
            "NETWORK_EVENT_DATA_STALL_AT_APP_LAYER"
        );
        "timeToNetworkEvents_msecs" =         (
            5168
        );
    };
    clientIdentifier = "com.apple.WebKit.Networking";
    connectionStatisticsReport =     {
        DNSAnswersCached = 0;
        "DNSResolvedTime_msecs" = 0;
        RTTvariance = 0;
        "appDataStallTimer_msecs" = 3;
        appReportingDataStallCount = 1;
        "bestRTT_msecs" = 0;
        betterRouteEventCount = 0;
        bytesDuplicate = 0;
        bytesIn = 2700000;
        bytesOut = 3800;
        bytesOutOfOrder = 0;
        bytesRetransmitted = 0;
        cellularFallback = 0;
        cellularRRCConnected = 0;
        connected = 1;
        connectedInterfaceType = "(unknown: 4)";
        "connectionEstablishmentTime_msecs" = 1;
        connectionReuseCount = 0;
        "currentRTT_msecs" = 0;
        "flowDuration_msecs" = 40208;
        interfaceType = "(unknown: 4)";
        kernelReportedStalls = 0;
        kernelReportingConnectionStalled = 0;
        kernelReportingReadStalled = 0;
        kernelReportingWriteStalled = 0;
        packetsDuplicate = 0;
        packetsIn = 210;
        packetsOut = 9;
        packetsOutOfOrder = 0;
        packetsRetransmitted = 0;
        "smoothedRTT_msecs" = 0;
        synRetransmissionCount = 0;
        tcpFastOpen = 0;
        "timeToConnectionEstablishment_msecs" = 2;
        "timeToConnectionStart_msecs" = 1;
        "timeToDNSResolved_msecs" = 0;
        "timeToDNSStart_msecs" = 0;
        trafficClass = 0;
    };
    delegated = 1;
    reportReason = "REPORT_REASON_DATA_STALL_AT_APP_LAYER";
    sourceAppIdentifier = "com.supermemo.sm-com";
}
Jul  6 10:13:59 iPad-xxx assistantd[268] <Error>: tcp_connection_tls_session_error_callback_imp 7 __tcp_connection_tls_session_callback_write_block_invoke.434 error 22
Jul  6 10:13:59 iPad-xxx assistantd[268] <Error>: NSURLSessionStreamTask: TCPConnection read invalidated by closed connection
Jul  6 10:13:59 iPad-xxx networkd[87] <Error>: -[NETAWDManager reportStats:metricID:] AWDServerConnection newMetricContainerWithIdentifier failed for metric 2686980, server 0x16d62570, not reporting:
<AWDMPTCPConnectionReport: 0x16d3ab50> {
    "client_id" = assistantd;
    "establishment_cellular_fallback" = 0;
    "establishment_failure_error" = 0;
    "establishment_forced_tcp_fallback" = 0;
    "establishment_interface_name" = en0;
    "establishment_success" = 1;
    "establishment_syn_retransmits" = 0;
    "establishment_tcp_fallback" = 0;
    "establishment_time" = "0.0573505";
    "interface_reports" =     (
                {
            "data_in_KB" = 5;
            "data_out_KB" = 2;
            "interface_name" = en0;
            "post_connect_subflow_failure_errors" =             (
            );
            "post_connect_tcp_fallback_count" = 0;
            "secondary_flow_failure_count" = 0;
            "secondary_flow_success_count" = 0;
        }
    );
    "post_connect_multi_homed" = 1;
    "post_connect_session_lifetime" = "42.711159041";
    "post_connect_single_homed" = 0;
    "post_connect_subflow_attempt_count" = 2;
    "post_connect_subflow_max_subflow_count" = 1;
    "subflow_switching_count" = 0;
}

WKWebView 使用一些安全协议从 OS 获取文件?有人知道如何处理吗?

我终于解决了。我必须实现 UIViewController 方法:

-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
    if (self.presentedViewController){
        [super dismissViewControllerAnimated:flag completion:completion]; 
}