javascriptcore

Swift blocks not working

陌路散爱 提交于 2019-11-29 03:32:21
问题 I've been trying to figure out how to use JavaScriptCore in swift. I'm running into problems however when I have to deal with blocks as arguments, seems like the block is run immediately and the arguments gets the return value of the block. What am I doing wrong? Working Objective C code: JSContext* context = [[JSContext alloc] initWithVirtualMachine:[[JSVirtualMachine alloc] init]]; context[@"test"] = ^(NSString *string) { //code }; What I've tried: 1: var ctx = JSContext(virtualMachine

iOS7新JavaScriptCore框架入门介绍

别等时光非礼了梦想. 提交于 2019-11-28 22:31:39
前阵子,Apple正式发布了新的iOS 7系统,最大最直观的改变在于界面变得小清新范了,我也提到《iOS,你真的越来越像Android了》。不过对于移动开发者来说,除了要适应Xcode 5,最应该关注的还是iOS 7在开发接口的上的变化。概览Apple提供的官方文档《What’s New in iOS》,最最让我欣喜的是iOS 7中加入了JavaScriptCore框架。该框架让Objective-C和JavaScript代码直接的交互变得更加的简单方便。 JavaScriptCore 这个框架其实只是基于webkit中以C/C++实现的JavaScriptCore的一个包装,在旧版本iOS开发中,很多开发者也会自行将webkit的库引入项目编译使用。不过虽然iOS7把它当成了标准库,可惜目前,我还没有在Apple Developer中找到像之前文章中收集的那样的官方文档介绍这个框架的具体使用方法。 好在还可以在Xcode中找到头文件,而且里面的注释对每个类和方法的功能写得还算清楚,再结合网上仅有的几篇文章的介绍,我也在此简单入门一下JavaScriptCore框架在基本数据类型上的使用。在另一篇《JavaScriptCore框架在iOS7中的对象交互和管理》中,我更深入地介绍该框架在对象上的使用。 JavaScriptCore中的类 在项目中引入JavaScriptCore后

Trigger objective C method from javascript using JavaScriptCore in iOS 7 in ViewControllers

▼魔方 西西 提交于 2019-11-28 18:03:12
I am loading a url in the webview which has below HTML and javascript function call. Now I am looking into when user touches submit button in webview it should call any method in viewController. Webview should load url(webview delegate) is one approach but is there any new way to get know when javascript function is called by webview should inform viewcontroller or trigger any method in view controller. I am not looking for this solution this we need to - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

How is an ObjC JS bridge translated?

帅比萌擦擦* 提交于 2019-11-28 10:53:39
问题 How does the JavaScriptCore framework translate JavaScript objects into Objective-C objects, and vice versa? Does the bridge use the same binary protocol to communicate for both of the target languages? 回答1: The Objective-C framework introduced with iOS7 does all the heavy lifting for you. You don't need to think of the objects as the same binary but interpreted differently - the framework performs a copy when converting between ObjC and Javascript. From JSValue.h: // Conversion between

How to bridge TVML/JavaScriptCore to UIKit/Objective-C (Swift)?

允我心安 提交于 2019-11-28 09:44:32
So far tvOS supports two ways to make tv apps, TVML and UIKit, and there is no official mentions about how to mix up things to make a TVML (that is basically XML) User Interface with the native counter part for the app logic and I/O (like playback, streaming, iCloud persistence, etc). So, which is the best solution to mix TVML and UIKit in a new tvOS app? In the following I have tried a solution following code snippets adapted from Apple Forums and related questions about JavaScriptCore to ObjC/Swift binding. This is a simple wrapper class in your Swift project. import UIKit import TVMLKit

How to get JSContext from WKWebView

不羁的心 提交于 2019-11-27 14:27:27
问题 In UIWebView, I can get JSContext through: [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"] The same way doesn't work in WKWebView and app crashes when it arrives this line of code. Is there a way to get JSContext in WKWebView? thanks in advance. 回答1: You cannot obtain the context, because layout and javascript is handled on another process. Instead, add scripts to your webview configuration, and set your view controller (or another object) as the script message

How to bridge TVML/JavaScriptCore to UIKit/Objective-C (Swift)?

旧城冷巷雨未停 提交于 2019-11-27 03:09:32
问题 So far tvOS supports two ways to make tv apps, TVML and UIKit, and there is no official mentions about how to mix up things to make a TVML (that is basically XML) User Interface with the native counter part for the app logic and I/O (like playback, streaming, iCloud persistence, etc). So, which is the best solution to mix TVML and UIKit in a new tvOS app? In the following I have tried a solution following code snippets adapted from Apple Forums and related questions about JavaScriptCore to