使用WKWebView可以在JavaScript和Swift/Obj-C本机代码之间进行同步通信吗?
这些是我尝试过但失败的方法.
方法1:使用脚本处理程序
WKWebView接收JS消息的新方法是使用userContentController:didReceiveScriptMessage:从JS调用的委托方法window.webkit.messageHandlers.myMsgHandler.postMessage('What's the meaning of life, native code?')
.这种方法的问题是在执行本机委托方法时,JS执行没有被阻止,所以我们不能通过立即调用webView.evaluateJavaScript("something = 42", completionHandler: nil).
示例(JavaScript)
var something;
function getSomething() {
    window.webkit.messageHandlers.myMsgHandler.postMessage("What's the meaning of life, native code?"); // Execution NOT blocking here :(
    return something;
}
getSomething();    // Returns undefined
Run Code Online (Sandbox Code Playgroud)
示例(Swift)
func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
    webView.evaluateJavaScript("something = 42", completionHandler: nil)
}
Run Code Online (Sandbox Code Playgroud)
方法2:使用自定义URL方案
在JS中,重定向使用window.location = "js://webView?hello=world"调用本机   WKNavigationDelegate方法,其中可以提取URL查询参数.但是,与UIWebView不同,委托方法不会阻止JS执行,因此立即调用evaluateJavaScript将值传递回JS也不起作用.
示例(JavaScript)
var something;
function getSomething() {
    window.location …Run Code Online (Sandbox Code Playgroud) 错误:
Error spawning child process: Permission denied
Run Code Online (Sandbox Code Playgroud)
在我尝试在Xcode模拟器中运行我的项目时,在控制台中弹出大约五到十次中的一个.发生这种情况时,项目不会运行.重新运行项目(Cmd-R再次)通常有效.在谷歌上找不到任何关于错误的提及,有没有人遇到过这种情况?
编辑2014-07-04,也会收到此错误.

运行XCode 5.1
干杯,保罗
在UIWebView,如果包含文本的输入元素具有焦点,并且按下按钮导致输入失去焦点,则随后双击输入以重新获得焦点并从弹出栏中选择剪切(或复制或粘贴)出现导致UIWebView崩溃的错误:
-[UIWebView cut:]: unrecognized selector sent to instance 0x10900ca60
Run Code Online (Sandbox Code Playgroud)
演示项目:https://github.com/guarani/WebViewDoubleTapTestTests.git
我认为这肯定是一个UIWebView错误,任何想法?
为了完整起见,这是我的网页视图的内容,
<html>
    <head>
    </head>
    <body>
        <br><br>
        <input type="text">
        <input type="button">
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)
提交了Apple的Bug报告:15894403
更新2014/10/15:iOS 8.0.2中仍然存在错误(12A405)
我很想知道iOS应用程序如何安装在设备上的技术细节.让我解释一下我的情况,
我想知道应用程序如何安装,是否已添加到队列中?如果一个安装问题的应用程序无法安装,这将如何影响我要安装的其他应用程序.更具体地说,我想知道"等待"状态是什么意思?
这个问题不仅发生在我朋友的iPhone上,它在我的iPhone上也是如此.但是,我的iPhone有一个更严重的问题,我无法安装任何应用程序,因为所有应用程序都进入等待状态.
我朋友的iPhone(iPhone 5S)有iOS 7.0.4,我有iPhone 4S和iOS 7.0.3.
编辑03/12/13 - 09:30
这是在尝试安装期间的iPhone配置实用程序控制台输出.
... itunesstored[102] <Warning>: LaunchServices: installing placeholder for **.***.****.***********
... installd[62] <Notice>: 0x2c3000 handle_install_for_ls: Install of "/var/mobile/Library/Caches/com.apple.itunesstored/AppPlaceholders/4703876283909900519.app" requested by itunesstored
... installd[62] <Notice>: 0x2c3000 MobileInstallationInstall_Server: Installing app **.***.****.***********
... installd[62] <Notice>: 0x2c3000 install_application: Installing placeholder
... installd[62] <Notice>: 0x2c3000 MobileInstallationInstall_Server: Staging: 0.07s; Waiting: 0.00s; Installation: 0.24s; LS Sync: 0.00s; Overall: 0.38s
... filecoordinationd[128] <Warning>: sandboxing denied subscription to progress on category **.***.****.*********** …Run Code Online (Sandbox Code Playgroud) 在运行iOS 8.0(12A365)在iPod touch,canOpenURL:返回YES的tel://URL方案.
此外,在延迟5-10秒后openURL:返回nil .
UIApplication *application = [UIApplication sharedApplication];
NSURL *url = [NSURL URLWithString:@"tel://"];
if ([application canOpenURL:url])
{
    [application openURL:url];
}
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么canOpenURL:不回归NOiPod?facetime URL方案是不同的('facetime://')所以理论上它应该返回NO.
不幸的是我没有带iOS7的iPod进行测试,所以我无法将问题仅隔离到iOS8.
通过HTTPS连接到服务器时,我实现了该NSURLSessionDelegate方法URLSession:didReceiveChallenge:completionHandler:来实现一些自定义功能.
问题是这个委托方法只在第一次发出请求时被调用(后续请求不会调用此方法).我的自定义功能要求为每个请求调用委托方法.
这是一个例子:
- (IBAction)reload:(id)sender {
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration] delegate:self delegateQueue:nil];
    // Note that https://www.example.com is not the site I'm really connecting to.
    NSURL *URL = [NSURL URLWithString:@"https://www.example.com"];
    NSMutableURLRequest *URLRequest = [NSMutableURLRequest requestWithURL:URL];
    [[session dataTaskWithRequest:URLRequest
                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                    // Response received here.
                }] resume];
}
#pragma NSURLSessionDelegate
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
    // Called only for the first request, subsequent requests …Run Code Online (Sandbox Code Playgroud) <div id="header">
    <div>My</div>
    <div>Header</div>
</div>
<div id="content"></div>
Run Code Online (Sandbox Code Playgroud)
在上面的标记中,如何让内容填充屏幕的其余部分(无滚动)?如果标题具有固定高度,我知道如何使用绝对位置执行此操作,但我的标题高度是由其内容动态设置的(因此该网站在移动设备上具有响应能力。)
顺便说一句:我正在寻找仅 CSS 的解决方案,因为我认为 JavaScript 不适合此类任务。
多谢,