[英]iphone - JavaScriptCore Framework / library
有沒有人在 iOS 項目中使用過 JavaScriptCore 框架/庫? 我在現有框架列表中看不到任何此類框架,因此我從 Apple 開源網站http://www.opensource.apple.com/release/ios-40/下載了源代碼
現在我想知道我需要做什么才能將它集成到我的應用程序中。 這些 API 是否已經存在於 SDK 中,我可以通過僅復制標題來調用方法,還是需要將所有源代碼復制到項目中?
我有一個工作項目,它只是復制和導入標題。 但我無法理解它是如何工作的。 它有一個在啟動時調用的方法如下。
#include <dlfcn.h>
@implementation JSCocoaSymbolFetcher
+ (void)populateJavascriptCoreSymbols
{
_JSEvaluateScript = dlsym(RTLD_DEFAULT, "JSEvaluateScript");
_JSGarbageCollect = dlsym(RTLD_DEFAULT, "JSGarbageCollect");
_JSGlobalContextCreate = dlsym(RTLD_DEFAULT, "JSGlobalContextCreate");
_JSGlobalContextRetain = dlsym(RTLD_DEFAULT, "JSGlobalContextRetain");
_JSGlobalContextRelease = dlsym(RTLD_DEFAULT, "JSGlobalContextRelease");
_JSContextGetGlobalObject = dlsym(RTLD_DEFAULT, "JSContextGetGlobalObject");
_JSClassCreate = dlsym(RTLD_DEFAULT, "JSClassCreate");
_JSClassRetain = dlsym(RTLD_DEFAULT, "JSClassRetain");
.
.
.//other similar code
.
}
在@implementation 之前它也有這樣的方法
JSValueRef (*_JSEvaluateScript)(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
return _JSEvaluateScript(ctx, script, thisObject, sourceURL, startingLineNumber, exception);
}
void (*_JSGarbageCollect)(JSContextRef ctx);
void JSGarbageCollect(JSContextRef ctx)
{
return _JSGarbageCollect(ctx);
}
所以我的問題是
1) 有人嘗試過使用 JavaScriptCore for iPhone 應用程序嗎? 如果是怎么辦?
2) dlsym 方法是做什么的?
3)最后提到的方法是如何工作的? 例如void (*_JSGarbageCollect)(JSContextRef ctx); void JSGarbageCollect(JSContextRef ctx) { return _JSGarbageCollect(ctx); }
void (*_JSGarbageCollect)(JSContextRef ctx); void JSGarbageCollect(JSContextRef ctx) { return _JSGarbageCollect(ctx); }
您可以將 JavaScriptCore 與您的應用程序捆綁在一起,但您必須將整個項目包含在您的應用程序中。 有關更多詳細信息,請參閱http://www.phoboslab.org/log/2011/04/ios-and-javascript-for-real-this-time 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.