【问题标题】:iphone - JavaScriptCore Framework / libraryiphone - JavaScriptCore 框架/库
【发布时间】:2011-08-14 12:59:33
【问题描述】:

有没有人在 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); }

【问题讨论】:

  • 我相信你不能直接在 iOS 应用中使用 JavaScriptCore。执行 JS 的唯一允许方式是 UIWebView。如果你问我,那真是太蹩脚了。
  • 但是如果我们不能在iOS应用中使用,为什么Apple会提供源代码opensource.apple.com/release/ios-40呢?
  • @Squeegy 不再正确,它们允许您在应用程序中运行解释器,只要它在应用商店审核后不下载代码。

标签: iphone objective-c frameworks ios-frameworks


【解决方案1】:

您可以将 JavaScriptCore 与您的应用程序捆绑在一起,但您必须将整个项目包含在您的应用程序中。详情请见http://www.phoboslab.org/log/2011/04/ios-and-javascript-for-real-this-time

【讨论】:

  • 您提供的链接并没有真正提供关于应如何将苹果提供的代码构建为 xcode 项目以供 iOS 运行的良好信息,而且您必须为他们更改的 jscore 付费。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-17
  • 1970-01-01
  • 2011-06-11
  • 1970-01-01
相关资源
最近更新 更多