您的位置:首页 > 移动开发 > IOS开发

cordova iOS 下插件的使用遇到的问题和解决方法

2016-09-10 09:55 567 查看
前段时间调试了一个Android平台的Cordova应用,已经上线使用,感觉IOS下应该只需要打包上传app store就可以了,

但是现实总是很无情,模拟器调试都好好的,到了真机调试就问题不断,我也是呵呵了,进过几天的折腾,需要趁热赶紧

总结一下,免得以后又走弯路,也给大家一点参考资料,每个人的环境不尽相同,我写的也只能参考,不能保证在你的

系统下按这个方法就可以解决问题:

-----------------------------

先说第一个问题:

插件安装:

我按之前的安卓版本的插件安装方法:

cordova plugin add <cordova-plugin>   

Xcode下提示:Plugin not found, or is not a CDVPlugin 没有在config.xml中添加任何东西后经落实 命令需要加--save 参数:

cordova plugin add <cordova-plugin> --save

按这个命令把所有需要的插件重新安装一遍,发现还是不生效,有大神说需要把plugins下的ios.json删除,重新编译加载

一下,按此方法,果然可行,网络状态和设备状态对象都已经可用。

--------------------------

第二个问题:

虽然安装了Cordova-plugin-dialogs这个对话框插件:

可是在页面中使用alert()的时候,还是js得格式,标题是当前页面的文件名,没有截图可惜了,

在官方文档中,plugins一章中发现了这样一段话,写在最前面,如下:

This plugin provides access to some native dialog UI elements via a global navigator.notification object.

Although the object is attached to the global scoped navigator, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {

    console.log(navigator.notification);

}

英文一般,大概的意思就是,navigator.notification需要在设备准备好以后使用,就是上面的代码,需要写在onDeviceReady使用,

navigator.notification.alert(message, alertCallback, [title], [buttonName])

不用回调函数的话,这样写navigator.notification.alert("用户名不能为空!",null,"提示","确定");

然后把所有页面都重新调整了一遍,现在页面提示弹出的就是原生IOS对话框了,吃透官方文档很重要,贴一下我的config.xml文件,大家参考:

<?xml version='1.0' encoding='utf-8'?>

<widget id="cn.jybd.bi" version="1.0.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

    <name>应用名字</name>

    <description>   

        ********

    </description>

    <author email="dev@cordova.apache.org" href="http://cordova.io"> 

        **********       

    </author>

    <preference name="BackupWebStorage" value="none" />

    <preference name="WebViewBounce" value="false" />

    <preference name="DisallowOverscroll" value="true" />

    <content src="index.html" />

    <plugin name="cordova-plugin-whitelist" spec="1" />

    <access origin="*" />

    <allow-intent href="http://*/*" />

    <allow-intent href="https://*/*" />

    <allow-intent href="tel:*" />

    <allow-intent href="sms:*" />

    <allow-intent href="mailto:*" />

    <allow-intent href="geo:*" />

    <platform name="android">

        <allow-intent href="market:*" />

    </platform>

    <platform name="ios">

        <allow-intent href="itms:*" />

        <allow-intent href="itms-apps:*" />

    </platform>

    <plugin name="cordova-plugin-device" spec="~1.1.2" />

    <plugin name="cordova-plugin-dialogs" spec="~1.2.1" />

    <plugin name="cordova-plugin-network-information" spec="~1.2.1" />

</widget>

还有疑问可以邮件联系我: dsb2008@126.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  插件 cordova