CDVPlugin类ChildBrowserCommand(pluginName:ChildBrowserCommand)不存在

时间:2012-06-25 06:57:25

标签: iphone cordova salesforce phonegap-plugins

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

当我运行应用程序时,我能够看到登录屏幕。这是截图: enter image description here

当我点击“登录”按钮时,没有发生任何事情,我在同一页面。我已经在salesforceWrapper.js文件中包含了我的cosumer密钥,如下所示:

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

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

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'

将ChildBrowserCommand和ChildBrowser字段添加到Cordova.plist。 enter image description here

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

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

这是我的Xcode项目截图:

enter image description here

我已解决了CDVPlugin引用问题,并遇到了WebKit discarded an uncaught exception问题。我该如何解决这个问题?

通过在Crodova.plist中向ExternalHosts添加额外参数来解决这个问题。 enter image description here

3 个答案:

答案 0 :(得分:2)

对于遇到此问题的其他任何人,

问题可能是因为事件处理程序未正确绑定。 - 或者不止一次(最有可能)。

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

答案 1 :(得分:0)

  • 您是否编辑过Cordova.plist文件以包含ChildBrowser插件所需的映射?
  • 您是否在项目中正确包含了ChildBrowser插件的.h .m源代码?
  • 您是否已将childbrowser.js文件包含在index.html文件中?

这些问题通常会导致问题。

答案 2 :(得分:0)

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

即。改变这个(ChildBrowserCommand.m - &gt; showWebPage)

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

To This:

#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