使用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
最满意答案
Memcached没有Windows官方dll版本。
您可以自己从PECL源代码编译它,也可以使用其他人预编译的dll: http : //shikii.net/blog/installing-memcached-for-php-5-3-on-windows-7/
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 ...
-
PHP Memcached完全向后兼容Memcache吗?(Is PHP Memcached fully backwards compatible with Memcache?)[2022-03-26]
我不确定PECL Memcache项目是怎么回事,但是基础Github项目已经更新以支持PHP7,但仍未发布任何官方容量(我也需要这个,所以我一直在关注它)。 几周前,Remi repo(CentOS / Fedora)基于这些更新发布了PECL包,看起来很稳定。 如果你需要这个我建议你拉Github仓库并建立PECL扩展。 没有官方发布,这是我唯一可以向你推荐的东西。 这样您就不必破解旧类来处理现有代码。 https://github.com/websupport-sk/pecl-memcache (非官 ... -
memcached的Python?(Python memcached?)[2022-05-31]
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 ...
-
Nginx和memcached(Nginx and memcached)[2022-05-10]
我从来没有听说过你的花括号表示法,也找不到任何关于它的信息。 我不会说它不存在。 但是,最简单的操作方法是使用不同的分隔符,这些分隔符不能被误解为变量的一部分。 喜欢这个: 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上使用memcached(Using memcached on XAMPP)[2022-03-11]
您没有在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(本机库)与Memcached相同吗?(In PHP, is Memcached (the native library) the same as Memcached?)[2021-12-14]
不,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)