【问题标题】:PhoneGap.exec not workingPhoneGap.exec 不工作
【发布时间】:2011-05-10 14:14:54
【问题描述】:

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

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

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

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

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

有什么帮助吗?

非常感谢

【问题讨论】:

    标签: javascript api plugins cordova


    【解决方案1】:

    问题已解决。 基本上,我在应用程序委托 .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 ]; 
    } 
    }
    

    【讨论】:

      【解决方案2】:

      我怀疑我的 PhoneGap.exec 无法正常工作。所以我潜入了 phonegap.js 文件。然后添加了一些调试警报。我收到错误消息“ReferenceError:找不到变量 PluginManager”。 如果您遇到同样的问题,请更新 phonegap.js 文件。我的被​​损坏了一个。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-10
        • 1970-01-01
        • 2019-01-19
        • 1970-01-01
        • 2018-12-22
        • 2016-04-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多