javascript - Cordova 1.9 和 native 控件插件兼容性

标签 javascript cordova

我发现原生控件插件在 1.6 版本之前的 cordova/phonegao 上运行良好。但我无法再用这段代码让它工作了:

newLoc = location.href.substring(0, location.href.lastIndexOf("/") + 1);
// Initializating TabBar
nativeControls = window.plugins.nativeControls;
nativeControls.createTabBar();
// Back Button
nativeControls.createTabBarItem("page1", "Page 1", "www/images/pound.png", {
    "onSelect": function() {
        $.mobile.changePage("#page1", {
            transition: 'reverse slide'
        });
        nativeControls.setNavBarTitle("Page 1");
        nativeControls.selectTabBarItem("page1");
        selectedTabBarItem = "page1";
    }
});
// Home tab
nativeControls.createTabBarItem("page2", "Page 2", "www/images/pound.png", {
    "onSelect": function() {
        if (selectedTabBarItem == "page1") {
            $.mobile.changePage("#page2", {
                transition: 'slide'
            });
        } else {
            $.mobile.changePage("#page2", {
                transition: 'reverse slide'
            });
        }
        nativeControls.setNavBarTitle("Page 2");
        nativeControls.selectTabBarItem("page2");
        selectedTabBarItem = "page2";
    }
});
// About tab
nativeControls.createTabBarItem("page3", "Page 3", "www/images/question.png", {
    "onSelect": function() {
        $.mobile.changePage("#page3", {
            transition: 'slide'
        });
        nativeControls.setNavBarTitle("Page 3");
        nativeControls.selectTabBarItem("page3");
        selectedTabBarItem = "page3";
    }
});
// Compile the TabBar
nativeControls.showTabBar();
nativeControls.showTabBarItems("page1", "page2", "page3");
selectedTabBarItem = "page1";
nativeControls.selectTabBarItem("page1");
// Setup NavBar
nativeControls.createNavBar();
nativeControls.setNavBarTitle("Page 1");
nativeControls.setupLeftNavButton("?", "", "onLeftNavButton");
//nativeControls.hideLeftNavButton();
nativeControls.setupRightNavButton("About", "", "onRightNavButton");
nativeControls.showNavBar();
}

查看js文件,似乎现在需要cordova.exec();

有人成功了吗? iOS 和 iPhone 的插件有什么区别?

最佳答案

错误的原因是 Cordova 不再支持 window.plugins

解决办法:

按如下方式修改您的调用脚本(可能在您的 onDeviceReady() 函数中 - 如果您使用的话,这可能位于您的 controls.js 文件中:

// nativeControls = window.plugins.nativeControls; // get rid of (or comment out)
   nativeControls = new NativeControls(); // use this line instead

已修复并可与 Cordova 2.0 配合使用:-)

希望有帮助

附录:实际上这只会让您完成一半 - 您仍然需要编辑 xCode 文件 NativeControls.m

关于javascript - Cordova 1.9 和 native 控件插件兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11525503/

相关文章:

javascript - 根据数组中的小时计算日期的出现次数

javascript - 两个单选按钮类别

javascript - 导航器地理定位 getCurrentPosition 不起作用

java - GWT、PhoneGap 和视频 VLC

ios - 我的应用程序只能在后台运行 ios 10

javascript - 如何停止 "dragover"事件上的卡顿

javascript - fadeOut 不会在 Firefox 中正确设置动画

android - 为 ios 和 android 删除 phonegap 中的启动画面

ios5 - 从Phonegap访问IOS中的通知中心

javascript - 有没有办法在phonegap angularjs项目中实现拖放?