javascript - PhoneGap.exec 不工作

标签 javascript api plugins cordova

我目前正在为 PhoneGap 编写一个 HelloWorld 插件,只是为了测试他的功能。我正在关注 official documentation . 我在 Index.html 页面的 onDeviceReady() 函数中添加了以下代码:

        window.plugins.testplugin.action(
        function methodA() {
        alert("A");
        },function methodB() {
        alert("B");
        }
    );

Objective-C 模块只是随机调用两个回调之一。不幸的是什么也没有发生。我试图从同一个 onDeviceReady() 内部调用一些其他 PhoneGap API 作为通知 API,只是为了确保它正常工作,但在这种情况下也没有。看起来图书馆根本不工作,但如果我删除它:

    <script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script>

deviceready 事件被停止触发。这意味着库以某种方式处于事件状态但无法正常工作。

有什么帮助吗?

非常感谢

最佳答案

问题已解决。 基本上,我在应用程序委托(delegate) .m 文件中所做的修改是为了避免应用程序在 Safari(版本 0.9.5)中打开外部链接:

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest
   *)request navigationType:(UIWebViewNavigationType)navigationType
{ 
  return YES
}

以某种方式损害了 PhoneGap 库的功能。正确的做法是:

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest
   *)request navigationType:(UIWebViewNavigationType)navigationType
{ 
NSURL *url = [request URL]; 
// add any other schemes you want to support, or perform additional 
// tests on the url before deciding what to do -jm 
if( [[url scheme] isEqualToString:@"http"] || 
   [[url scheme] isEqualToString:@"https"]) 
{ 
    [[UIApplication sharedApplication] openURL:url]; 
    return YES; 
} 

else 
{ 
    return [ super webView:theWebView shouldStartLoadWithRequest:request 
            navigationType:navigationType ]; 
} 
}

关于javascript - PhoneGap.exec 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5951435/

相关文章:

javascript - 等待未知数量的ajax请求完成

Node.js 在不超过一定限制的情况下尽快调用函数

python - XML 解析器语法错误

android - ADB 启动失败确保插件配置正确

javascript - 使用Cesium JS更改标签的偏移量

JavaScript 固定数组或对象长度?

Android Lint 错误 : Class requires API level 3, 当前最小值为 1

.net - MEF 加载 GAC 中需要 DLL 的 DLL

eclipse - 如何在弹出菜单中添加项目?

javascript - 使用 jQuery 在工具提示中显示表格