简体   繁体   English

PhoneGap.exec无法正常工作

[英]PhoneGap.exec not working

I'm currently writing an HelloWorld plugin for PhoneGap,just to test his functionalities.I'm following the official documentation . 我目前正在为PhoneGap编写一个HelloWorld插件,只是为了测试其功能。我正在阅读官方文档 I added to the onDeviceReady() function inside my Index.html page the following code: 我在Index.html页面内的onDeviceReady()函数中添加了以下代码:

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

the objective-C module simply calls randomly one of the two callbacks. Objective-C模块只是简单地随机调用两个回调之一。 Unfortunately nothing happens. 不幸的是没有任何反应。 I've tried to call from inside the same onDeviceReady() some other PhoneGap API as the notification one,just to assure it's working, but nothing also in this case. 我试图从相同的onDeviceReady()内部调用其他PhoneGap API作为通知对象,只是为了确保它能正常工作,但在这种情况下也没有任何作用。 It looks like the library is not working at all,but if I remove this: 看来该库根本无法正常工作,但是如果我删除了它:

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

the deviceready event is stopped from being fired. deviceready事件停止触发。 This means that somehow the library is active but not working properly. 这意味着该库在某种程度上处于活动状态,但无法正常工作。

Any help? 有什么帮助吗?

thanks a lot 非常感谢

Problem Solved. 问题解决了。 Basically, the modification in the application delegate .m file I did in order to avoid the app from opening external links in Safari (in version 0.9.5): 基本上,我对应用程序委托.m文件所做的修改是为了避免该应用程序在Safari中打开外部链接(在0.9.5版中):

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

was, somehow, compromising the PhoneGap library functionalities. 某种程度上损害了PhoneGap库的功能。 The correct approach is: 正确的方法是:

- (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 ]; 
} 
}

I was suspecting that my PhoneGap.exec not working. 我怀疑我的PhoneGap.exec无法正常工作。 So I sneaked in to the phonegap.js file. 所以我潜入了phonegap.js文件。 Then added some debugging alert. 然后添加了一些调试警报。 I was getting error message "ReferenceError: can't find variable PluginManager". 我收到错误消息“ ReferenceError:找不到变量PluginManager”。 If you are having the same problem then update the phonegap.js file. 如果您遇到相同的问题,请更新phonegap.js文件。 Mine was corrupted one. 我的被​​破坏了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM