首页 \ 问答 \ 使用Native iOS App中的变量调用Javascript函数(Calling Javascript Function With Variables from Native iOS App)

使用Native iOS App中的变量调用Javascript函数(Calling Javascript Function With Variables from Native iOS App)

我目前有一个成功加载html文件的Web视图。 我有这样做的方法看起来像:

- (EmailView *)loadHTMLIntoEmailView:(EmailView *)emailView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"inlineAttachmentTemplate" ofType:@"html"];
    NSData *htmlData = [NSData dataWithContentsOfFile:path];
    NSString *resourceURL = [[NSBundle mainBundle] resourcePath];
    resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
    resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//",resourceURL]];

    [emailView.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL];
    return emailView;
 }

我看到的html文件如下:

<!doctype html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="inlineAttachmentTemplateStyling.css">

<script>
function myFunction()
   {
    document.write("Hello from my html file!!!!");

   }
</script>      

</head>
<body id="body">
 <div id="container">
     <img id="testImage" src="fauxImageAttachment2.JPG" />
 </div><!-- #container -->
</body>
</html>

这适用于图像显示在webview中。 如果我将document.write从函数中取出并将其直接放在脚本标记内,则文本将显示在webview中。 但是,我需要能够调用一个函数(来自我的Objective C方法),该函数允许文本显示在webview中,最终我还需要传递这个函数一些变量。 目前,我甚至无法弄清楚如何调用javascript函数。

我看了这个例子, 你能用PhoneGap和iOS调用本机代码(不是回调)中的javascript函数吗? ,并尝试将以下行添加到我的目标C方法:

    [emailView.webView stringByEvaluatingJavaScriptFromString:@"myFunction()"];

但是这不会调用函数...或者至少文本没有出现在webview中。
我是一个新手程序员,根本不了解javascript - 有人能突出我做错了什么吗?


I currently have a web view which successfully loads an html file. The method I have that does this looks like:

- (EmailView *)loadHTMLIntoEmailView:(EmailView *)emailView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"inlineAttachmentTemplate" ofType:@"html"];
    NSData *htmlData = [NSData dataWithContentsOfFile:path];
    NSString *resourceURL = [[NSBundle mainBundle] resourcePath];
    resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
    resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//",resourceURL]];

    [emailView.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL];
    return emailView;
 }

The html file I have looks like:

<!doctype html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="inlineAttachmentTemplateStyling.css">

<script>
function myFunction()
   {
    document.write("Hello from my html file!!!!");

   }
</script>      

</head>
<body id="body">
 <div id="container">
     <img id="testImage" src="fauxImageAttachment2.JPG" />
 </div><!-- #container -->
</body>
</html>

This works in that the image appears in the webview. If I take the document.write out of a function and just place it directly inside the script tags, then the text appears in the webview. However, I need to be able to call a function (from my Objective C method) that allows the text to be displayed in the webview, and ultimately I also need to pass this function some variables. At the moment, I cannot even figure out how to get the javascript function to be called.

I looked at this example, Can you call a javascript function from native code (not in a callback) using PhoneGap and iOS?, and tried adding the following line to my objective C method:

    [emailView.webView stringByEvaluatingJavaScriptFromString:@"myFunction()"];

But this does not call the function... or at least the text does not appear in the webview.
I'm quite a novice programmer and don't know much about javascript at all - can anyone highlight what I am doing incorrectly?


原文:https://stackoverflow.com/questions/18513213
更新时间:2022-03-10 10:03

最满意答案

Memcached没有Windows官方dll版本。

您可以自己从PECL源代码编译它,也可以使用其他人预编译的dll: http//shikii.net/blog/installing-memcached-for-php-5-3-on-windows-7/

另请参见: Windows上的Memcached(不是memcache)PHP扩展


Memcached has no official dll release for windows.

You can either compile it yourself from the PECL source or use a precompiled dll from someone else : http://shikii.net/blog/installing-memcached-for-php-5-3-on-windows-7/

See also : Memcached (not memcache) PHP extension on Windows

相关问答

更多
  • 来自memcached手册: EXPIRATION TIME:如果它是非零(Unix时间或从当前时间以秒为单位的偏移量),则保证客户端在到期时间到达后将无法检索此项目(按服务器时间测量)。 所以在到期时间之后应该为NULL。 如果发生,否则你在Memcached或这个库中发现了一个错误。 你确定你使用的是“Memcached”而不是“Memcache”。 从您链接的lib的来源: $this->client_type = class_exists('Memcache') ? "Memcache" : (cl ...
  • 我不确定PECL Memcache项目是怎么回事,但是基础Github项目已经更新以支持PHP7,但仍未发布任何官方容量(我也需要这个,所以我一直在关注它)。 几周前,Remi repo(CentOS / Fedora)基于这些更新发布了PECL包,看起来很稳定。 如果你需要这个我建议你拉Github仓库并建立PECL扩展。 没有官方发布,这是我唯一可以向你推荐的东西。 这样您就不必破解旧类来处理现有代码。 https://github.com/websupport-sk/pecl-memcache (非官 ...
  • https://pypi.python.org/pypi/python-memcached/ : 该软件是memcached内存缓存守护进程的100%Python接口。 它是客户端软件,允许在一个或多个(可能是远程的)memcached服务器中存储值。 这意味着memcached作为独立的守护进程运行,独立于httpd ,并且您的代码可以像在数据库中一样将数据存储在该守护进程中。 实际上, memcached只不过是NoSQL数据库。 有关教程,请参阅Python中使用的python-memcache(me ...
  • 正如Jesper建议的那样,我使用Dalli memcached客户端解决了这个问题。 As Jesper suggested, I solved the issue using Dalli memcached client.
  • Memcached没有Windows官方dll版本。 您可以自己从PECL源代码编译它,也可以使用其他人预编译的dll: http : //shikii.net/blog/installing-memcached-for-php-5-3-on-windows-7/ 另请参见: Windows上的Memcached(不是memcache)PHP扩展 Memcached has no official dll release for windows. You can either compile it your ...
  • 将symfony与memcached集成的简单方法是使用现有的bundle。 我使用leaseweb / memcache-bundle,它非常简单 - 只需按照以下说明操作即可: https : //github.com/LeaseWeb/LswMemcacheBundle 。 并记得首先启动memcached;) 然而,要将其与FOSUserBundle完全集成,但它确实支持php会话。 An easy way to integrate symfony with memcached is to use ...
  • memcached模块是不支持php压缩值来解压缩的 请参阅此链接https://github.com/3rd-Eden/node-memcached/issues/173 如果我们尝试使用memcached模块存储数据,它将作为原始数据存储。 我们必须选择另一种压缩技术(例如:snappy)来存储压缩数据而不是存储原始数据。 memcached module is does not support php compressed value to decompress See this link https ...
  • 我从来没有听说过你的花括号表示法,也找不到任何关于它的信息。 我不会说它不存在。 但是,最简单的操作方法是使用不同的分隔符,这些分隔符不能被误解为变量的一部分。 喜欢这个: set $memcached_key $cookie_devicetype:$request_uri; I have never heard of your curly bracket notation and cannot find any information about it. I won't say it doesn't e ...
  • 您没有在XAMPP PHP版本上安装Memcached扩展:如果您在UNIX环境中工作,您只需使用命令安装memcached // Step 1. $ sudo apt-get install memcached // Step 2. $ sudo apt-get install php5-memcached // Step 3. $ sudo /etc/init.d/apache2 restart 如果您使用Windows环境,则应使用Memcache扩展而不是Memcached。 在下面 ...
  • 不,PHP的“memcached”是一个PHP扩展,提供了进入memcached 守护进程的入口( 真正的 memcached,如果你愿意的话) Nope, PHP's "memcached" is a PHP extension that provides an entryway into the memcached daemon (the real memcached, if you will)

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)