cordova + ionic 使用中碰到的一些问题--非原创

http://blog.sina.com.cn/s/blog_537517170102w5vj.html 源地址

1、No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.
解决办法
index.html 中添加
《meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"》

2、ionic 隐藏 nav-bar
文档上来看,需要在controller中调用 <wbr> $ionicNavBarDelegate 例如 .controller('DashCtrl', function ($scope, $ionicNavBarDelegate) { <wbr> <wbr> <wbr> $ionicNavBarDelegate.showBar(false); }) 但没起作用。最后在模板中使用标签方法 <a name="baidusnap4" style="text-decoration: underline; color: rgb(118, 95, 71);"></a>hide-nav-bar = "true"
该方法起作用。

3、 ng-model 与 input 值的问题
例如 <wbr> <wbr> input type="text" ng-model="querystr"
ng-model绑定到$scope.querystr 时,model会根据 text输入自动变化,但在controller中将
$scope.querystr=''时 ,text input的值不会产生变化。
并且在使用ng-model时,无法使用
angular.element(document).find(selector).val("some value");方式进行赋值。
解决方法是在controller 中,设置一个结构,如
$scope.queryMode ={querystr:''};
在input 中绑定 <wbr> ng-model = "queryModel.querystr"
则controller中重设 <wbr> <wbr> $scope.queryMode.querystr = '';
绑定生效,input 清空。

4、cordova插件 ,在ripple中弹出错误窗口
如果安装cordova插件,如keyboard,statusbar 等, 会在ripple中抛各种错,并且每次加载会弹出窗口,让你写JSON回调, 这个是ripple的BUG,不支持自定义插件, 去掉弹窗的办法是在app.js上方,即定义angular.module()的上方

var annoyingDialog = parent.document.getElementByIdx_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x('exec-dialog');

上句中的x_x 去掉,新浪自动添加的。

if (annoyingDialog) annoyingDialog.outerHTML = "";

弹窗将不再出现,但输出窗口中的ripple.js中的错误仍会,你可以过滤,也可以不管。

5、使用极光推送,按照github上的说明文档,加入插件后总是无法编译,查看

是由于 platform/android/AndroidManifest.xml <wbr>中

meta-data android:name=JPUSH_APPKEY android:value=aaabbbbmn9QITAv0Oe

重复,每次build总会生成两条键值

经查在plug/android.json 中,有两条重复生成的语句,删掉一个,即可。

6、ionic关于IFAME的调用
因为使用第三方接口,会造成跑到应用外的地址,ionic无法控制外部连接回到应用,因此一般使用iframe方式
打开外部连接,并加一个headbar用来返回到应用,如在modal中打开外部地址
如html中
<wbr>《script id="login.html" type="text/ng-template"》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《ion-modal-view》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《ion-header-bar align-title="center" class="bar-positive"》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《div class="buttons"》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《button <wbr> class="button button-clear button-icon icon ion-ios-arrow-back"》《/button》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《button ng-click="closeModal()" class="button button-clear button-icon icon "》取消《/button》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《/div》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《h1 class="title"》LOGIN《/h1》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《/ion-header-bar》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《ion-content scroll="true" class="has-header no-padding"》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《iframe id="ifmr2" data-tap-disabled="true" ng-src="{{chatStru.paySrc}}"》《/iframe》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《/ion-content》
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 《/ion-modal-view》
《/script》

controller中
$scope.tt = new Date().getMilliseconds();
$scope.chatStru = {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> paySrc: $sce.trustAsResourceUrl('http://xxx.om/testlogin.jsp?tt='+$scope.tt),
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> token: "",
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> hasToken: false
<wbr> <wbr> <wbr> };
$ionicModal.fromTemplateUrl('login.html', {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> scope: $scope,
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> animation: 'slide-in-up'
<wbr> <wbr> <wbr> }).then(function (modal) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.modal = modal;
<wbr> <wbr> <wbr> });

<wbr> <wbr> <wbr> $scope.openModal = function () {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.modal.show();
<wbr> <wbr> <wbr> };
<wbr> <wbr> <wbr> <wbr> $scope.closeModal = function () {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.modal.hide();
<wbr> <wbr> <wbr> };

但这样的问题是在于,页面完成后,你必须通过手动点击返回,并且无法进行数据的传递,这个在html5中其实已经有了非常完美的解决方法就是postMessage()
在远端的被iframe的页面中,加入JS
window.onload=function(){
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> window.parent.postMessage('logined','*');
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }

并在inoic的controller中加入
<wbr>window.addEventListener('message', function (e) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> var data = e.data;
//这里返回的是 logined,相当于传递参数回来。
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.modal.hide();
<wbr> <wbr> <wbr> }, false);

<wbr> 你会发现,你即接收到了data,同时又关闭了该modal ,而不需要手动关闭。

当然,你可以将 addEventListener() 放到 <wbr>$scope.openModal <wbr>

然后在 $scope.closeModal 中 removeEventListener()

<wbr>$scope.openModal = function () {

<wbr> <wbr> <wbr> <wbr> var tt = new Date().getMilliseconds();

<wbr> <wbr> <wbr> <wbr> $scope.chatStru.paySrc = $sce.trustAsResourceUrl('http://xxx.cn/oe/testlogin.jsp?tt=' + tt);

<wbr> <wbr> <wbr> <wbr> $scope.modal.show();

<wbr> <wbr> <wbr> <wbr> window.addEventListener('message', function (e) {

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> var data = e.data;

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.chatStru.hasToken = true;

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.modal.hide();

<wbr> <wbr> <wbr> <wbr> }, false);

<wbr> <wbr> };

<wbr> <wbr> // function to close the modal

<wbr> <wbr> $scope.closeModal = function () {

<wbr> <wbr> <wbr> <wbr> $scope.modal.hide();

<wbr> <wbr> <wbr> <wbr> if ($scope.chatStru.hasToken) {

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> window.removeEventListener('message', function () { }, false);

<wbr> <wbr> <wbr> <wbr> }

<wbr> <wbr> };

最终可以这样写

<wbr>var handel = function (e) {

<wbr> <wbr> <wbr> <wbr> var data = e.data;

<wbr> <wbr> <wbr> <wbr> if (data.id > 0) { <wbr>// 传回来的为json{id:1,msg:'aaa'}

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> if (!$scope.chatStru.hasToken) {

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.chatStru.hasToken = true;

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.modal.hide();

<wbr> <wbr> <wbr> <wbr> } else {

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $scope.chatStru.hasToken = false;

<wbr> <wbr> <wbr> <wbr> }

<wbr> <wbr> };

<wbr> <wbr> $scope.openModal = function () {

<wbr> <wbr> <wbr> <wbr> var tt = new Date().getMilliseconds();

<wbr> <wbr> <wbr> <wbr> $scope.chatStru.paySrc = $sce.trustAsResourceUrl('http://xxx.cn/oe/testlogin.jsp?tt=' + tt);

<wbr> <wbr> <wbr> <wbr> $scope.modal.show();

<wbr> <wbr> <wbr> <wbr> if (!$scope.chatStru.hasToken) {

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> window.addEventListener('message', handel, false);

<wbr> <wbr> <wbr> <wbr> }

<wbr> <wbr> };

<wbr> <wbr> <wbr>

<wbr> <wbr> $scope.closeModal = function () {

<wbr> <wbr> <wbr> <wbr> $scope.modal.hide();

<wbr> <wbr> <wbr> <wbr> if ($scope.chatStru.hasToken) {

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> window.removeEventListener('message', handel, false);

<wbr> <wbr> <wbr> <wbr> }

<wbr> <wbr> };

7、使用android studio 运行cordova项目
直接使用platfrom目录里的gradle 可以在android studio中直接导入 cordova的项目,但运行模拟器时出现
Cannot <wbr>reload <wbr>AVD <wbr>list: <wbr>cvc-enumeration-valid: <wbr>Value <wbr>'280dpi' <wbr>is <wbr>not <wbr>facet-valid <wbr>with <wbr>respect <wbr>to <wbr>enumeration <wbr>'[ldpi, <wbr>mdpi, <wbr>tvdpi, <wbr>hdpi, <wbr>xhdpi, <wbr>400dpi, <wbr>xxhdpi, <wbr>560dpi, <wbr>xxxhdpi]'. <wbr>It <wbr>must <wbr>be <wbr>a <wbr>value <wbr>from <wbr>the <wbr>enumeration.
Error <wbr>parsing <wbr>D:\sdkforas\android-sdk-windows\system-images\android-22\android-wear\armeabi-v7a\devices.xml
cvc-enumeration-valid: <wbr>Value <wbr>'280dpi' <wbr>is <wbr>not <wbr>facet-valid <wbr>with <wbr>respect <wbr>to <wbr>enumeration <wbr>'[ldpi, <wbr>mdpi, <wbr>tvdpi, <wbr>hdpi, <wbr>xhdpi, <wbr>400dpi, <wbr>xxhdpi, <wbr>560dpi, <wbr>xxxhdpi]'. <wbr>It <wbr>must <wbr>be <wbr>a <wbr>value <wbr>from <wbr>the <wbr>enumeration.
Error <wbr>parsing <wbr>D:\sdkforas\android-sdk-windows\system-images\android-22\android-wear\x86\devices.xml
解决方法 :
用/sdk/tools/lib/devices.xml去替换 system-images\android-22\android-wear\x86\devices.xml和system-images \android-22\android-wear\armeabi-v7a\devices.xml中的devices.xml

8、 android studio 中 gradle 失败
gradle <wbr>project <wbr>sync <wbr>failed.Basic <wbr>functionality(e.g.editing,debugging) <wbr>will <wbr>not <wbr>work <wbr>properly.
解决方法:android <wbr>studio中,点击 <wbr>tools <wbr>->Android->sync <wbr>project <wbr>with <wbr>gradles <wbr>files.

9、加载远程js或css 出现 Refused to load the script <wbr> 或 Refused to load the stylesheet
because it violates the following ....
例如 index.html中 加载字体
《link href='http://fonts.useso.com/css?family=RobotoDraft:400,500,700,400italic' rel='stylesheet'》
可在index.html添加安全许可
《meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' http://fonts.useso.com ; script-src 'self' 'unsafe-inline' 'unsafe-eval';"》
直接加根域名即可,另外不要带引号 js <wbr> 需要添加在 script-src 中。

10 、 ionic 中 弹出键盘遮挡住输入框
在config.xml 中修改全屏为FALSE并添加 <wbr> adjustPan <wbr> (adjstResize没有成功)
<wbr>《preference name="Fullscreen" value="False" /》
<wbr> 《preference name="android-windowSoftInputMode" value="adjustPan"/》

11、ionic监听滚动
网上的示例xxx.bind('scroll',function(){.....}),很容易将页面跑死, 换个思路,使用监听touch
var targetPos = window.screen.availHeight;
<wbr>$("#scdiv").on("touchend", function () {
if (currpos > 10 && currpos < targetPos / 4) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $ionicScrollDelegate.$getByHandle('homescroll').scrollTo(0, 0, true);
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> return false;
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> } else if (currpos >= targetPos / 4 && currpos <= targetPos - 10) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $ionicScrollDelegate.$getByHandle('homescroll').scrollTo(0, targetPos - 64, true);
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> return false;
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
})
当触摸结束时,判断当前的位移,来做一些操作。这样在性能上提高了许多。
$ionicScrollDelegate.$getByHandle 操作的是在html中定义的delegate-handle
如《ion-content id="scdiv" delegate-handle="homescroll"》
12、 APP开启检测网络并提示开启
需要三个插件
1、https://github.com/apache/cordova-plugin-network-information
2、https://github.com/apache/cordova-plugin-dialogs
3、https://github.com/deefactorial/Cordova-open-native-settings

然后在APP.JS中,divicesReady中
$ionicPlatform.ready(function () {
if (navigator.connection) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> var tmptypes = navigator.connection.type;
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> if (tmptypes.toUpperCase().indexOf('NONE') > -1 || tmptypes.toUpperCase().indexOf('UNKNOWN') > -1) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> if (navigator.notification) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> navigator.notification.confirm(
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> '您的设备未开启网络',
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> function (buttonIndex) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> if (buttonIndex == 1) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> if (cordova.plugins.settings) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> cordova.plugins.settings.openSetting("wifi", function () { console.log("network setting openning"); }, function () { console.log("open network setting failed"); });
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }, <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> // callback to invoke with index of button pressed
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> '提示', <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> // title
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> ['开启', '取消'] <wbr> <wbr> <wbr> <wbr> // buttonLabels
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> );
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
})

其中openSettings中可设置以下本地设置

var <wbr>settingNames <wbr>= <wbr>array(

<wbr> <wbr> <wbr> <wbr>"open",

<wbr> <wbr> <wbr> <wbr>"accessibility",

<wbr> <wbr> <wbr> <wbr>"add_account",

<wbr> <wbr> <wbr> <wbr>"airplane_mode",

<wbr> <wbr> <wbr> <wbr>"apn",

<wbr> <wbr> <wbr> <wbr>"application_details",

<wbr> <wbr> <wbr> <wbr>"application_development",

<wbr> <wbr> <wbr> <wbr>"application",

<wbr> <wbr> <wbr> <wbr>"bluetooth",

<wbr> <wbr> <wbr> <wbr>"captioning",

<wbr> <wbr> <wbr> <wbr>"cast",

<wbr> <wbr> <wbr> <wbr>"data_roaming",

<wbr> <wbr> <wbr> <wbr>"date",

<wbr> <wbr> <wbr> <wbr>"device_info",

<wbr> <wbr> <wbr> <wbr>"display",

<wbr> <wbr> <wbr> <wbr>"dream",

<wbr> <wbr> <wbr> <wbr>"home",

<wbr> <wbr> <wbr> <wbr>"input_method",

<wbr> <wbr> <wbr> <wbr>"input_method_subtype",

<wbr> <wbr> <wbr> <wbr>"internal_storage",

<wbr> <wbr> <wbr> <wbr>"locale",

<wbr> <wbr> <wbr> <wbr>"location_source",

<wbr> <wbr> <wbr> <wbr>"manage_all_applications",

<wbr> <wbr> <wbr> <wbr>"manage_applications",

<wbr> <wbr> <wbr> <wbr>"memory_card",

<wbr> <wbr> <wbr> <wbr>"network_operator",

<wbr> <wbr> <wbr> <wbr>"nfcsharing",

<wbr> <wbr> <wbr> <wbr>"nfc_payment",

<wbr> <wbr> <wbr> <wbr>"nfc_settings",

<wbr> <wbr> <wbr> <wbr>"print",

<wbr> <wbr> <wbr> <wbr>"privacy",

<wbr> <wbr> <wbr> <wbr>"quick_launch",

<wbr> <wbr> <wbr> <wbr>"search",

<wbr> <wbr> <wbr> <wbr>"security",

<wbr> <wbr> <wbr> <wbr>"settings",

<wbr> <wbr> <wbr> <wbr>"show_regulatory_info",

<wbr> <wbr> <wbr> <wbr>"sound",

<wbr> <wbr> <wbr> <wbr>"sync",

<wbr> <wbr> <wbr> <wbr>"usage_access",

<wbr> <wbr> <wbr> <wbr>"user_dictionary",

<wbr> <wbr> <wbr> <wbr>"voice_input",

<wbr> <wbr> <wbr> <wbr>"wifi_ip",

<wbr> <wbr> <wbr> <wbr>"wifi",

<wbr> <wbr> <wbr> <wbr>"wireless");

其中相关网络的为wifi <wbr> 移动数据开启未找到。谁试出了是哪个请告诉我

13、$sate.go <wbr> 和 $stateParams 传参及收参
在 controller1 中使用 <wbr> $state.go('statename',{id:1}) ;传递参数
在 statename 相对应的 <wbr> controller2 中接收参数
$scope.id = $stateParams.id;
注意,此处必须在router.js 中设置 statename 的参数形式
如.state('statename ', {
<wbr> <wbr> <wbr> url: '/statename ',
<wbr> <wbr> <wbr> params: { 'id': null },
<wbr> <wbr> <wbr> templateUrl: 'templates/Users/statename .html',
<wbr> <wbr> <wbr> controller: 'controller2 '
})
其中params: { 'id': null }, 对应$state传的参,若不设,则必为undefined

14、关于ionic中想底部加一长按钮,随页面滚动位置不变,例如

最初的方案是在 ion-content <wbr> 外 ion-view 内添加一层
div .....style= ..... position:fixed <wbr> <wbr> <wbr> bottom:0px;之类,但最终发现,在不同分辨率下位置并不正确
基本可确定是因为statusbar等的缘故,仔细看了下ionic.css最终发现,太简单了
div class="tabs" <wbr> 就可以了。

15、php中取值问题
ionic中用的$http <wbr> method:post ,params........在PHP中用$_POST取不到值, 改成 $_Request 就行了。

16、使用vs2015 release
会提示使用发布配置进行调试时,Android 程序包必须已签名。要配置 Android 签名,请按照 http://go.microsoft.com/fwlink/?LinkID=613579 中的说明操作(该网页很难打开)
实际需要在项目根目录的build.json中添加生成的keystore
{
<wbr> <wbr> <wbr> <wbr> "android": {
<wbr> <wbr> <wbr> <wbr> <wbr> "release": {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> "keystore": "E:\Projects\android.keystore",
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> "storePassword": "*******",
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> "alias": "********",
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> "password": "*******",
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> "keystoreType": ""
<wbr> <wbr> <wbr> <wbr> <wbr> }
<wbr> <wbr> <wbr> <wbr> }
<wbr>}
至于生成keystore 请百度,只要有jdk 运行命令就OK

17、ionic 的滚动优化
在app.js中的config 块中,加入
$ionicConfigProvider.scrolling.jsScrolling(false);
默认所有的滚动使用native,会比js的滚动快很多,并且很平滑,
但这样做的话,无法使用一些效果,如has-bouncing="true"(仿苹果的一种上下拉显示背景的弹性效果)
那你可以在特定的view中,ion-content中加入overflow-scroll="false",则该view保持js滚动

18、微信支付
支付宝支付非常简单,文档也很丰富,微信的相对来说低了不止一个档次,当然最郁闷的一件事是
经过了数天的查错,发现微信的totalfee 居然是以分为单位,换句话来说,你传价格时,只会有整数
如果出现0.01,那必然出错。

19 ion-header-bar 下总是有条横线,即使设为border:none也没有作用。经查,添加background-size: 100% 0px; 即可解决。

20 极光推送设置分组
服务器端网上代码很多,不多说了,客户端中有个坑
<wbr>window.plugins.jPushPlugin.setTagsWithAlias(tagname,alias);
其中tagname/alias都为string , (看网上好多人这么搞的,不明白他们怎么成功的?)
返回错误Error reading tagAlias JSON
再试
window.plugins.jPushPlugin.setTagsWithAlias([tagname],alias);
这样OK。 换句话说, tags是数组, alias是string

21 <wbr> ionicLoading 以及网络超时设置
app.js中,先注册rootScope的广播
.run(function ($ionicPlatform,$ionicLoading,ToastService, $rootScope) {
<wbr> <wbr> <wbr> $rootScope.$on('loading:show', function () {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $ionicLoading.show({ template: '努力为您加载中...' })
<wbr> <wbr> <wbr> })
<wbr> <wbr> <wbr> $rootScope.$on('loading:hide', function () {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $ionicLoading.hide()
<wbr> <wbr> <wbr> })

.config(function ($httpProvider) {
$httpProvider.defaults.timeout = 5000; //默认超时为5秒
$httpProvider.interceptors.push(function ($rootScope) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> return {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> request: function (config) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $rootScope.$broadcast('loading:show')
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> return config
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> },
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> response: function (response) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $rootScope.$broadcast('loading:hide')
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> return response
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> },
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> responseError: function (response) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $rootScope.$broadcast('loading:hide')
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> return response

<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> },
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> requestError: function (config) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $rootScope.$broadcast('loading:hide')
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> return config
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }
<wbr> <wbr> <wbr> })

如果以上不能解决网络超时问题,loading仍然会几十秒后才消失,
那就在service.js中
<wbr>QueryAllByKeywords: function (params) {
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> var deferred = $q.defer();
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> //var url = ConfigService.getApi() + "queryAllByParams.php";
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> $http({
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> method: 'GET',
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> url: url
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> , params: params,
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> timeout:5000
<wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }).success( <wbr> ....
中显式设置,这种就只能每个方法去设置了。

22、 ionic升级到1.3后,button-clear 按钮不正常显示
如:《button class="button button-clear button-large icon ion-ios-search light"》《/button》
原本显示是白色搜索按钮,但现在不显示,在电脑端发现鼠标移动上时会显示。
因使用了ionic-material库,估计是该库原因
应急解决办法《button class="button button-clear button-large icon ion-ios-search light" style="color:#fff"》 为字体加个白色即可。

23、ion-scroll 不滚动
原代码 在ionic1.2.4下正常,更新至1.3 无法滚动
《ion-scroll <wbr> id="photoscroll" <wbr> <wbr> delegate-handle="phoeoradio" direction="x" zooming="false" 》
增加overflow-scroll="false" 即可。

24、splash screen 在安卓上变形
发现在部分1080P下,按cordova splash screen 的 <wbr> screen-xhdpi-portrait.png(720*960) 设置的启动画面,会变形挤瘦,需要在config.xml 中加入
《preference name="SplashMaintainAspectRati<wbr>o" value="true" /》
不强制拉伸即可。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,968评论 6 482
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,601评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 153,220评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,416评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,425评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,144评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,432评论 3 401
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,088评论 0 261
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,586评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,028评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,137评论 1 334
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,783评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,343评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,333评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,559评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,595评论 2 355
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,901评论 2 345

推荐阅读更多精彩内容