【问题标题】:CDVPlugin class ChildBrowserCommand (pluginName: ChildBrowserCommand) does not existCDVPlugin 类 ChildBrowserCommand (pluginName: ChildBrowserCommand) 不存在
【发布时间】:2012-06-25 06:57:24
【问题描述】:

我创建了一个基于 PhoneGap 的应用程序,并包含了我从该链接下载的相同代码:Building PhoneGap Mobile Applications Powered by Database.com

当我运行应用程序时,我可以看到登录屏幕。这是屏幕截图:

当我点击登录按钮时,什么都没有发生,我在同一页面中。我已经将我的 cosumer 密钥包含在 salesforceWrapper.js 文件中,如下所示:

function SalesforceWrapper() {
    /* AUTHENTICATION PARAMETERS */
    this.loginUrl = 'https://login.salesforce.com/';
    this.clientId = 'sadsadasdadadasdasdasdsadasdas.dsddsd_sdsds.dsdsdsdsdsds';
    this.redirectUri = 'https://login.salesforce.com/services/oauth2/success';

    /* CLASS VARIABLES */
    this.cb = ChildBrowser.install(); //ChildBrowser in PhoneGap
    this.client = new forcetk.Client(this.clientId, this.loginUrl); //forceTk client instance

    this.init();
}

为什么我无法重定向到 salesforce 登录页面?这是控制台输出:

2012-06-25 16:20:53.023 J[2396:13403] Opening Url : https://login.salesforce.com/services/oauth2/authorize?display=touch&response_type=token&client_id=sadsadasdadadasdasdasdsadasdas.dsddsd_sdsds.dsdsdsdsdsds&redirect_uri=https%3A//login.salesforce.com/services/oauth2/success
2012-06-25 16:20:53.024 J[2396:13403] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> Application tried to present modally an active controller <MainViewController: 0x9a67dc0>.
2012-06-25 16:20:53.034 J[2396:13403] ERROR whitelist rejection: url='https://login.salesforce.com/services/oauth2/authorize?display=touch&response_type=token&client_id=sadsadasdadadasdasdasdsadasdas.dsddsd_sdsds.dsdsdsdsdsds&redirect_uri=https%3A//login.salesforce.com/services/oauth2/success'

向 Cordova.plist 添加了 ChildBrowserCommand 和 ChildBrowser 字段。

在Index.html页面中包含脚本文件路径:

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

这是我的 Xcode 项目截图:

我已经解决了CDVPlugin 参考问题并得到了WebKit discarded an uncaught exception 问题。我该如何解决这个问题?

通过向 Crodova.plist 中的 ExternalHosts 添加额外参数来解决它。

【问题讨论】:

    标签: iphone cordova salesforce phonegap-plugins


    【解决方案1】:

    对于其他面临此问题的人,

    问题可能是由于事件处理程序没有正确绑定。 - 或多次绑定(很可能)。

    虽然必须对插件代码进行修补以防止其尝试多次绑定,但防止这种情况发生的简单方法是在 jQuery 中使用委托事件处理程序并确保事件绑定到目标恰好一次。

    【讨论】:

      【解决方案2】:
      • 您是否编辑了 Cordova.plist 文件以包含 ChildBrowser 插件所需的映射?
      • 您是否在项目中正确包含了 ChildBrowser 插件的 .h .m 源代码?
      • 您是否已包含 childbrowser.js 文件并将其加载到您的 index.html 文件中?

      通常是这些问题之一导致问题。

      【讨论】:

      • 是的。我在 plist 中添加了 2 个字段(ChildBrowser、ChildBrowserCommand)。
      • 并且在 index.html 中也包含了 childbrowser.js。
      • 我已将 ChildBrowser 文件放在 Plugins 文件夹中。你认为这会是问题吗。我已经编辑了我的帖子,请检查一次。
      • Ben Clayton 你知道我该如何解决这个问题吗:stackoverflow.com/questions/11191311/…
      • 很高兴您对原始问题进行了排序。抱歉,无法帮助您解决 oauth 问题!
      【解决方案3】:

      对于在 IOS 5 上遇到此问题的其他所有人,问题是 Childbrowser 尝试显示两次导致错误。一种解决方案是在显示代码周围抛出一个 try catch。

      即改变这个(ChildBrowserCommand.m -> showWebPage)

      #ifdef CORDOVA_FRAMEWORK
      CDVViewController* cont = (CDVViewController*)[ super viewController ];
      childBrowser.supportedOrientations = cont.supportedOrientations;
      childBrowser.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
      [ cont presentModalViewController:childBrowser animated:YES ];
      #endif
      

      到这里:

      #ifdef CORDOVA_FRAMEWORK
      CDVViewController* cont = (CDVViewController*)[ super viewController ];
      childBrowser.supportedOrientations = cont.supportedOrientations;
      childBrowser.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
      @try {
          [ cont presentModalViewController:childBrowser animated:YES ];
      }@catch(NSException * e){
          NSLog(@"ALready visible");
      }
      #endif
      

      【讨论】:

      • if(childBrowser.presentingViewController == nil){ [ cont presentModalViewController:childBrowser animated:YES ]; }
      猜你喜欢
      • 1970-01-01
      • 2016-08-19
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      相关资源
      最近更新 更多